Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

CStringArrayparam.cpp

Go to the documentation of this file.
00001 
00002 #include "CStringArrayparam.h"                                  
00003 #include <TCLInterpreter.h>
00004 #include <TCLResult.h>
00005 #include <TCLList.h>
00006 #include <vector>
00007 #include <RangeError.h>
00008 #include <stdio.h>
00009 
00015 CStringArrayparam::CStringArrayparam (const string& rKey, int nSize)
00016    : CConfigurationParameter(rKey), 
00017    m_aStrings(0),
00018    m_nSize(nSize)
00019 {   
00020     m_aStrings = new string[m_nSize];
00021 } 
00026  CStringArrayparam::~CStringArrayparam ( )  //Destructor - Delete dynamic objects
00027 {
00028     delete []m_aStrings;
00029 }
00034 CStringArrayparam::CStringArrayparam (const CStringArrayparam& rhs ) 
00035   : CConfigurationParameter (rhs),
00036   m_nSize(rhs.m_nSize)
00037  
00038 {
00039     m_aStrings = new string[m_nSize];
00040     for(int i =0; i < m_nSize; i++) {
00041         m_aStrings[i] = rhs.m_aStrings[i];
00042     }
00043 } 
00049 CStringArrayparam& 
00050 CStringArrayparam::operator= (const CStringArrayparam& rhs)
00051 { 
00052     if (this == &rhs) {
00053         delete []m_aStrings;
00054         m_nSize     = rhs.m_nSize;
00055         m_aStrings = new string[m_nSize]; 
00056     }
00057     return *this;
00058 }
00066 int 
00067 CStringArrayparam::operator== (const CStringArrayparam& rhs) const
00068 { 
00069 
00070     if(!CConfigurationParameter::operator==(rhs)) return 0;
00071     if(m_nSize != rhs.m_nSize) return 0;
00072     for(int i =0; i < m_nSize; i++) {
00073         if(m_aStrings[i] != rhs.m_aStrings[i]) return 0;
00074     }
00075     return 1;                      // Equality!.
00076 }
00077 
00078 // Functions for class CStringArrayparam
00079 
00087 string& 
00088 CStringArrayparam::operator[](int n)  
00089 {
00090      if((n < 0) || (n >= m_nSize)) {
00091        CRangeError r(0, m_nSize-1, n,
00092                      string("CStringArrayParam::operator[] bad index"));
00093        throw r;
00094      }
00095      return m_aStrings[n]; 
00096 }  
00097 
00111 int 
00112 CStringArrayparam::SetValue(CTCLInterpreter& rInterp, 
00113                             CTCLResult& rResult, 
00114                             const char* pValue)
00115 { 
00116     // First throw things up into a list and then split the list into a string vector:
00117     
00118     StringArray Values;
00119     try {
00120         CTCLList ValueList(&rInterp, pValue);
00121         ValueList.Split(Values);
00122     }
00123     catch(...) {
00124         rResult += "Configuration string array: ";
00125         rResult += getSwitch();
00126         rResult += " configuration list was badly formatted.";
00127         rResult += pValue;
00128         return TCL_ERROR;
00129     }
00130     
00131     // The size of the vector should be the same as the size of the
00132     // m_aStrings array:
00133     
00134     if(Values.size() != m_nSize) {
00135         rResult += "Configuration string array: ";
00136         rResult += " Size mismatch between the parameter list and \n";
00137         rResult +=  "the list. ";
00138         rResult += getSwitch();
00139         return TCL_ERROR;
00140     }
00141         
00142     // Copy the string vector into the string array:
00143     
00144     for(int i =0; i < m_nSize; i++) {
00145         m_aStrings[i] = Values[i];
00146     }
00147     return TCL_OK;
00148 }
00153 string
00154 CStringArrayparam::GetParameterFormat()
00155 {
00156     char result[100];
00157     sprintf(result, "string[%d]", m_nSize);
00158     return string(result);
00159 }

Generated on Fri Mar 12 13:04:04 2004 for Scripted Readout by doxygen 1.3.4