CAttributeList Class Reference

#include <CAttributeList.h>

Inheritance diagram for CAttributeList:

CMagic

List of all members.

Public Types

typedef map< string, pair
< char *, char * > > 
CBase

Public Member Functions

void check () const
list< string > getKeys () const
 CAttributeList (const char *const *const inAttributeList)
 CAttributeList (const list< pair< string, string > > &inAttributes)
 CAttributeList (const CAttributeList &inList)
const_iterator find (string inString) const
void add (const string &inFirst, const string &inSecond)
void add (const string &inAttribute, long inValue)
void add (const string &inAttribute, double inValue)
pair< bool, boolboolReadAttribute (const string &inAttribute) const
pair< bool, long > longReadAttribute (const string &inAttribute) const
pair< bool, double > doubleReadAttribute (const string &inAttribute) const
virtual pair< bool, string > stringReadAttribute (const string &inAttribute) const
void toXML (string &outString) const
 ~CAttributeList ()


Detailed Description

a simple class destined to contain attribute-value pairs in an easily accessible fashion

Definition at line 36 of file CAttributeList.h.


Member Typedef Documentation

typedef map<string,pair<char*,char*> > CAttributeList::CBase

Definition at line 43 of file CAttributeList.h.


Constructor & Destructor Documentation

CAttributeList::CAttributeList ( const char *const *const   inAttributeList  ) 

from expat

Definition at line 34 of file CAttributeList.cc.

References CMutex::lock(), and CMutex::unlock().

00034                                                                         {
00035   clear();
00036   if(inAttributeList){
00037     const char*const*  lAttributes(inAttributeList);
00038     while(lAttributes[0] && strlen(lAttributes[0])){
00039       if(strlen(lAttributes[0])>200){
00040   cerr << __FILE__ << ":" 
00041        << __LINE__ << ":" << flush
00042        << "lAttributes[0] too long:[" << endl
00043        << lAttributes[0]
00044        << "]ENDOF STRING"
00045        << endl;
00046       };//for debugging purposes DEBUG
00047       if(strlen(lAttributes[1])>200){
00048   cerr << __FILE__ << ":" 
00049        << __LINE__ << ":" << flush
00050        << "lAttributes[1] too long:[" << endl
00051        << lAttributes[1]
00052        << "]ENDOF STRING"
00053        << endl;
00054       };//for debugging purposes DEBUG
00055 #ifndef _IS_SEQUENCE_AL
00056       gMutex->lock();
00057       if(lAttributes[1]){
00058   //  cout << "[L" << strlen(lAttributes[1]) << "L]" << flush;
00059   if(strlen(lAttributes[1])){
00060     
00061     int lLen(strlen(lAttributes[1])+1);
00062     char* lBuffer(new char[lLen]);
00063     strcpy(lBuffer,lAttributes[1]);
00064     char* lBuffer2(new char[lLen]);
00065     strcpy(lBuffer2,lAttributes[1]);
00066 
00067     insert(make_pair(lAttributes[0],
00068          make_pair(lBuffer,lBuffer2)));
00069     
00070     //cout << "[" << lBuffer << "]" << flush;
00071     assert(strlen(operator[](lAttributes[0]).second)==lLen-1);
00072     assert(strlen(operator[](lAttributes[0]).first)==lLen-1);
00073   }else{
00074     char* lBuffer(new char[1]);
00075     lBuffer[0]=char(0);
00076     char* lBuffer2(new char[1]);
00077     lBuffer2[0]=char(0);
00078     insert(make_pair(string(lAttributes[0]),
00079          make_pair(lBuffer,lBuffer2)));
00080   }
00081       }
00082       gMutex->unlock();
00083 #else
00084       push_back(make_pair(string(lAttributes[0]),
00085         string((lAttributes[1] && strlen(lAttributes[1]))?lAttributes[1]:"")));
00086 #endif
00087       lAttributes+=2;
00088     }
00089   }
00090 }

CAttributeList::CAttributeList ( const list< pair< string, string > > &  inAttributes  ) 

from other c++

Definition at line 111 of file CAttributeList.cc.

References CMutex::lock(), and CMutex::unlock().

00111                                                                              {
00112       gMutex->lock();
00113 
00114   clear();
00115   for(list<pair <string,string> >::const_iterator i=inAttributes.begin();
00116       i!=inAttributes.end();
00117       i++){
00118     if(i->second.size()>200){
00119       cerr << __FILE__ << ":" 
00120      << __LINE__ << ":" << flush
00121      << "i->second too long:[" << endl
00122      << i->second
00123      << "]ENDOF STRING"
00124      << endl;
00125     }
00126 #ifndef _IS_SEQUENCE_AL
00127     int lLen(i->second.size()+1);
00128     char* lBuffer(new char[lLen]);
00129     strcpy(lBuffer,i->second.c_str());
00130     char* lBuffer2(new char[lLen]);
00131     strcpy(lBuffer2,i->second.c_str());
00132     insert(make_pair(i->first,
00133          make_pair(lBuffer,
00134              lBuffer2)));
00135     
00136     //    insert(*i); if the representation is map<string,string>
00137 #else
00138     push_back(*i);
00139 #endif
00140   }  
00141   gMutex->unlock();
00142 }

CAttributeList::CAttributeList ( const CAttributeList inList  ) 

copy constructor

Definition at line 143 of file CAttributeList.cc.

References CMutex::lock(), and CMutex::unlock().

00143                                                                 {
00144   gMutex->lock();
00145   clear();
00146   for(CAttributeList::const_iterator i=inAttributes.begin();
00147       i!=inAttributes.end();
00148       i++){
00149 #ifndef _IS_SEQUENCE_AL
00150     if(strcmp(i->second.first,
00151         i->second.second)){
00152       if(strcmp(i->second.first,
00153     i->second.second)){
00154   cout << "ASSERTION FAILED" << i->second.first << "/" << i->second.second << endl;
00155   assert(0);
00156       }
00157     }
00158     assert(!strcmp(i->second.first,
00159        i->second.second));
00160     int lLen(strlen(i->second.first)+1);
00161     char* lBuffer(new char[lLen]);
00162     strcpy(lBuffer,i->second.first);
00163     int lLen2(strlen(i->second.second)+1);
00164     char* lBuffer2(new char[lLen2]);
00165     strcpy(lBuffer2,i->second.second);
00166 
00167     insert(make_pair(i->first,make_pair(lBuffer,lBuffer2)));
00168 #else
00169     push_back(*i);
00170 #endif
00171   }  
00172   gMutex->unlock();
00173 }

CAttributeList::~CAttributeList (  ) 

the destructor in the case of char* as content it deletes the arrays of char.

Definition at line 91 of file CAttributeList.cc.

00091                                {
00092   //checkNPrint();
00093   for(iterator i=begin();
00094       i!=end();
00095       i++){
00096       
00097     if(strcmp(i->second.first,
00098        i->second.second)){
00099 #if __WORDSIZE==64 /* this should tell us what size a float* is, so that we can dump it properly.. */
00100       cout << "DELETING FAILED" << flush << int64_t(i->second.second) << flush << i->second.first << i->second.second << endl;
00101 #else
00102       cout << "DELETING FAILED" << flush << int32_t(i->second.second) << flush << i->second.first << i->second.second << endl;
00103 #endif
00104       assert(0);
00105     }
00106     delete[] i->second.first;
00107     delete[] i->second.second;
00108   }
00109 }


Member Function Documentation

void CAttributeList::check (  )  const

reading an attribute for strings

Reimplemented from CMagic.

Definition at line 393 of file CAttributeList.cc.

Referenced by CXMLElement::check(), CXMLElement::createNamedValueList(), and CAlgorithm::mergeAttributes().

00393                                {
00394   for(const_iterator i=begin();
00395       i!=end();
00396       i++){
00397     assert(!strcmp(i->second.second,
00398        i->second.first));
00399   }
00400 };

list< string > CAttributeList::getKeys (  )  const

Get the keys of all attributes in this list

Definition at line 408 of file CAttributeList.cc.

00408                                          {
00409   list<string> lReturnValue;
00410   // the following two implementations are equivalent
00411   transform(this->begin(),
00412       this->end(),
00413       back_inserter(lReturnValue),
00414       _CAL_getFirst<CAttributeList::mapped_type>
00415       );
00416 // #ifdef GCC30
00417 //   for(const_iterator i=begin();
00418 //       i!=end();
00419 //       i++){
00420 //     lReturnValue.push_back(i->first);
00421 //   }
00422 // #endif
00423   return lReturnValue;
00424 }

CAttributeList::const_iterator CAttributeList::find ( string  inString  )  const

finding in this

Definition at line 174 of file CAttributeList.cc.

Referenced by CAlgorithm::mergeAttributes(), and stringReadAttribute().

00174                                                                      {
00175   //check();
00176 
00177 #ifdef _PRINTOUTS_AL
00178   cout << endl
00179        << "CAttributeList::find("
00180        << flush;
00181   cout << inString
00182        << ") size " << flush;
00183   cout << size()
00184        << " "
00185        << inString.size()
00186        << endl;
00187 #endif  
00188 
00189 #ifndef _CAL_FIND_WORKAROUND
00190   return CAttributeList::CBase::find(inString);
00191 #else
00192   for(const_iterator i=begin();
00193       i!=end();
00194       i++){
00195 #ifdef _PRINTOUTS_AL
00196     cout << "~" << flush;
00197     cout << "[" << flush;
00198     cout << i->first <<flush;
00199     cout << "," << flush;
00200     cout << i->second << flush;
00201     cout << "]" << flush;
00202 #endif
00203 
00204     if(i->first==inString){
00205 #ifdef _PRINTOUTS_AL
00206       cout << "+" << flush;
00207 #endif
00208       return i;
00209     }
00210 #ifdef _PRINTOUTS_AL
00211     cout << "." << flush;
00212 #endif
00213   }
00214   cout << "-" << flush;
00215   return end();
00216 #endif
00217 }

void CAttributeList::add ( const string &  inFirst,
const string &  inSecond 
)

adding an attribute

Definition at line 218 of file CAttributeList.cc.

References CMagic::checkNPrint(), CMutex::lock(), and CMutex::unlock().

Referenced by CXMLElement::addAttribute(), and CAlgorithm::mergeAttributes().

00219                               {
00220   gMutex->lock();
00221 
00222 
00223 #ifdef _PRINTOUTS_AL
00224   checkNPrint();
00225   cout << "Adding to CAttributeList "
00226        << inFirst
00227        << " "
00228        << inSecond
00229        << endl;
00230 #endif
00231 
00232 #ifndef _IS_SEQUENCE_AL
00233   char* lBuffer=new char[inSecond.size()+1];
00234   lBuffer[inSecond.size()]=char(0);
00235   strncpy(lBuffer,inSecond.c_str(),inSecond.size());
00236   char* lBuffer1=new char[inSecond.size()+1];
00237   lBuffer1[inSecond.size()]=char(0);
00238   strncpy(lBuffer1,inSecond.c_str(),inSecond.size());
00239 
00240   operator[](inFirst)=make_pair(lBuffer,lBuffer1);
00241   //  (*this).insert(make_pair(inFirst,inSecond));
00242 #else
00243   (*this).push_back(make_pair(inFirst,inSecond));
00244 #endif
00245   gMutex->unlock();
00246 }

void CAttributeList::add ( const string &  inAttribute,
long  inValue 
)

adding an attribute for integers using the function for strings

adding an attribute for integers

Definition at line 248 of file CAttributeList.cc.

00248                                                               {
00249   char lBuffer[20];
00250   for(int i=0;
00251       i<20;
00252       i++){
00253     lBuffer[i]=0;
00254   }
00255   sprintf(lBuffer,
00256     "%ld",
00257     inValue);
00258   add(inAttribute,
00259       lBuffer);
00260 };

void CAttributeList::add ( const string &  inAttribute,
double  inValue 
)

adding an attribute for doubles using using the function for strings

adding an attribute for doubles

Definition at line 262 of file CAttributeList.cc.

00262                                                                 {
00263   char lBuffer[20];
00264 
00265   for(int i=0;
00266       i<20;
00267       i++){
00268     lBuffer[i]=0;
00269   }
00270   sprintf(lBuffer,
00271     "%lf",
00272     inValue);
00273   add(inAttribute,
00274       lBuffer);
00275 };

pair< bool, bool > CAttributeList::boolReadAttribute ( const string &  inAttribute  )  const

reading an attribute for booleans using stringReadAttribute it supports several pairs: yes/no true/false y/n

reading an attribute for integers

Definition at line 278 of file CAttributeList.cc.

References stringReadAttribute().

Referenced by CXMLElement::boolReadAttribute().

00278                                                                                {
00279   pair<bool,string> lReadAttribute=stringReadAttribute(inAttribute);
00280 
00281   if(!lReadAttribute.first){
00282     return make_pair(bool(0),bool(0));
00283   }else{
00284     char* lLastCorrectCharacter=0;
00285 
00286     bool lReturnValue=((lReadAttribute.second=="yes")
00287            ||
00288            (lReadAttribute.second=="y")
00289            ||
00290            (lReadAttribute.second=="true")
00291            ||
00292            (lReadAttribute.second=="t"));
00293     return make_pair(lReadAttribute.first,
00294          lReturnValue);
00295   }
00296 };

pair< bool, long > CAttributeList::longReadAttribute ( const string &  inAttribute  )  const

reading an attribute for integers using stringReadAttribute

reading an attribute for integers

Definition at line 298 of file CAttributeList.cc.

References stringReadAttribute().

Referenced by CXMLElement::longReadAttribute(), and startHierarchyElement().

00298                                                                                {
00299   pair<bool,string> lReadAttribute=stringReadAttribute(inAttribute);
00300 
00301   if(!lReadAttribute.first){
00302     return make_pair(bool(0),long(0));
00303   }else{
00304     char* lLastCorrectCharacter=0;
00305 
00306     long lReturnValue=strtol(lReadAttribute.second.c_str(),
00307            &lLastCorrectCharacter,
00308            10);
00309     bool lIsValid=!(*lLastCorrectCharacter);
00310     
00311     return make_pair(lIsValid,
00312          lReturnValue);
00313   }
00314 };

pair< bool, double > CAttributeList::doubleReadAttribute ( const string &  inAttribute  )  const

reading an attribute for doubles using stringReadAttribute

reading an attribute for doubles

Definition at line 316 of file CAttributeList.cc.

References stringReadAttribute().

Referenced by CXMLElement::doubleReadAttribute().

00316                                                                                    {
00317 #ifdef __D_CATTRIBUTELIST__DOUBLEREADATTRIBUTE__
00318   cout << "In doubleReadAttribute "
00319        << flush
00320        << endl;
00321 #endif
00322 
00323   pair<bool,string> lReadAttribute=stringReadAttribute(inAttribute);
00324 
00325 #ifdef __D_CATTRIBUTELIST__DOUBLEREADATTRIBUTE__
00326   cout << "AGAIN In doubleReadAttribute "
00327        << flush
00328        << endl;
00329 #endif
00330 
00331   if(!lReadAttribute.first){
00332     return make_pair(bool(0),
00333          double(0));
00334   }else{
00335     char* lLastCorrectCharacter=0;
00336 
00337     double lReturnValue=strtod(lReadAttribute.second.c_str(),
00338              &lLastCorrectCharacter);
00339     bool lIsValid=!(*lLastCorrectCharacter);
00340     
00341     return make_pair(lIsValid,
00342          lReturnValue);
00343   }
00344 };

pair< bool, string > CAttributeList::stringReadAttribute ( const string &  inAttribute  )  const [virtual]

reading an attribute for strings

All the attribute functions implement a primitive version of inheritance: We look also at the parents of this, if we do not find a given attribute in this.

this is virtual in order to plug in other methods of inheritance

reading an attribute for strings

Definition at line 346 of file CAttributeList.cc.

References CMagic::checkNPrint(), and find().

Referenced by boolReadAttribute(), doubleReadAttribute(), longReadAttribute(), newStartURL2FTSElement(), startHierarchyElement(), CI18nTranslator::startXMLElement(), and CXMLElement::stringReadAttribute().

00346                                                                                    {
00347   
00348   //check, if the magic number is correct at this time
00349 
00350 #ifdef _PRINTOUTS_AL
00351   checkNPrint();
00352   cout << inAttribute 
00353        << endl 
00354        << flush;
00355 #endif
00356 
00357 #ifdef _PRINTOUTS_AL
00358   find(inAttribute);
00359   cout << "came back from find()" << flush;
00360 #endif
00361 
00362   CAttributeList::const_iterator lFoundPosition(find(inAttribute));
00363 
00364 #ifdef _PRINTOUTS_AL
00365   cout << "came back 2nd time from mAttributes.find()" << flush;
00366 #endif
00367 
00368   if(lFoundPosition != end()){
00369     assert(!strcmp(lFoundPosition->second.first,
00370        lFoundPosition->second.second));
00371 
00372     string lFoundString(lFoundPosition->second.first);
00373 
00374     pair<bool,string> lReturnValue=make_pair(bool(1),
00375                lFoundString);
00376     return lReturnValue;
00377   }
00378   return make_pair(bool(0),
00379        string(""));
00380 };

void CAttributeList::toXML ( string &  outString  )  const

Outputting a string to XML

reading an attribute for strings

Definition at line 382 of file CAttributeList.cc.

Referenced by CXMLElement::toXML().

00382                                                 {
00383   outString += " ";
00384   for(const_iterator i=begin();
00385       i!=end();
00386       i++){
00387     outString += i->first + "=\"" + i->second.first + "\" ";
00388     assert(!strcmp(i->second.second,
00389        i->second.first));
00390   }
00391 };


The documentation for this class was generated from the following files:

Generated on Wed Jan 7 00:31:05 2009 for Gift by  doxygen 1.5.6