Ignore:
Timestamp:
04/12/11 11:48:48 (13 years ago)
Author:
hozdoba
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/xmlio/attribute_map.cpp

    r152 r171  
    1414      CAttributeMap::~CAttributeMap(void) 
    1515      { /* Ne rien faire de plus */ } 
    16  
     16       
     17      ///-------------------------------------------------------------- 
     18       
    1719      bool CAttributeMap::hasAttribute(const StdString & key) const 
    18       { return (this->find(key) != this->end()); } 
    19  
     20      {  
     21         return (this->find(key) != this->end());  
     22      } 
     23       
     24      //--------------------------------------------------------------- 
     25       
    2026      void CAttributeMap::setAttribute(const StdString & key, CAttribute * const attr) 
    2127      { 
     
    2834         this->find(key)->second->setAnyValue(attr->getAnyValue()); 
    2935      } 
    30  
     36       
     37      //--------------------------------------------------------------- 
     38       
    3139      CAttribute * CAttributeMap::operator[](const StdString & key) 
    3240      { 
     
    3644         return (SuperClassMap::operator[](key)); 
    3745      } 
    38  
     46       
     47      //--------------------------------------------------------------- 
     48       
    3949      StdString CAttributeMap::toString(void) const 
    4050      { 
     
    5161         return (oss.str()); 
    5262      } 
    53  
     63       
     64      //--------------------------------------------------------------- 
     65       
    5466      void CAttributeMap::fromString(const StdString & str) 
    55       { ERROR("CAttributeMap::fromString(const StdString & str)", 
    56              << "[ str = " << str << "] Not implemented yet !"); } 
     67      {  
     68         ERROR("CAttributeMap::fromString(const StdString & str)", 
     69               << "[ str = " << str << "] Not implemented yet !");  
     70      } 
     71       
     72      //--------------------------------------------------------------- 
    5773 
    5874      //StdOStream & operator << (StdOStream & os, const CAttributeMap & attributmap) 
    5975      //{ os << attributmap.toString(); return (os); } 
    60  
     76       
     77      //--------------------------------------------------------------- 
     78       
    6179      void CAttributeMap::setAttributes(const xml::THashAttributes & attributes) 
    6280      { 
     
    7189            } 
    7290      } 
    73  
     91       
     92      //--------------------------------------------------------------- 
     93       
    7494      void CAttributeMap::setAttributes(const CAttributeMap * const _parent) 
    7595      { 
     
    90110         } 
    91111      } 
     112       
     113      //--------------------------------------------------------------- 
     114       
     115      void CAttributeMap::toBinary(StdOStream & os) const 
     116      { 
     117         typedef std::pair<StdString, CAttribute*> StdStrAttPair; 
     118         SuperClassMap::const_iterator it = this->begin(), end = this->end(); 
     119          
     120         const StdSize nbatt = SuperClassMap::size(); 
     121         os.write (reinterpret_cast<const char*>(&nbatt) , sizeof(StdSize)); 
     122          
     123         for (; it != end; it++) 
     124         { 
     125            const StdString & key   = it->first; 
     126            const CAttribute* value = it->second;             
     127            const StdSize size = key.size(); 
     128             
     129            os.write (reinterpret_cast<const char*>(&size) , sizeof(StdSize)); 
     130            os.write (key.data(), size * sizeof(char)); 
     131             
     132            if (!value->isEmpty()) 
     133            { 
     134               bool b = true; 
     135               os.write (reinterpret_cast<const char*>(&b) , sizeof(bool)); 
     136               value->toBinary(os); 
     137            } 
     138            else  
     139            { 
     140               bool b = false; 
     141               os.write (reinterpret_cast<const char*>(&b) , sizeof(bool)); 
     142            } 
     143         } 
     144      } 
     145       
     146      //--------------------------------------------------------------- 
     147       
     148      void CAttributeMap::fromBinary(StdIStream & is) 
     149      { 
     150         StdSize nbatt = 0; 
     151         is.read (reinterpret_cast<char*>(&nbatt), sizeof(StdSize)); 
     152          
     153         for (StdSize i = 0; i < nbatt; i++) 
     154         { 
     155            bool hasValue = false; 
     156            StdSize size  = 0; 
     157            is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); 
     158            StdString key(size, ' '); 
     159            is.read (const_cast<char *>(key.data()), size * sizeof(char)); 
     160             
     161            if (!this->hasAttribute(key)) 
     162               ERROR("CAttributeMap::fromBinary(StdIStream & is)", 
     163                     << "[ key = " << key << "] key not found !");  
     164                      
     165            is.read (reinterpret_cast<char*>(&hasValue), sizeof(bool)); 
     166             
     167            if (hasValue)           
     168               this->operator[](key)->fromBinary(is); 
     169         } 
     170      } 
     171       
     172      ///-------------------------------------------------------------- 
    92173 
    93174   } // namespace tree 
Note: See TracChangeset for help on using the changeset viewer.