Changeset 171 for XMLIO_V2/dev/dev_rv/src/xmlio/attribute_map.cpp
- Timestamp:
- 04/12/11 11:48:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/xmlio/attribute_map.cpp
r152 r171 14 14 CAttributeMap::~CAttributeMap(void) 15 15 { /* Ne rien faire de plus */ } 16 16 17 ///-------------------------------------------------------------- 18 17 19 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 20 26 void CAttributeMap::setAttribute(const StdString & key, CAttribute * const attr) 21 27 { … … 28 34 this->find(key)->second->setAnyValue(attr->getAnyValue()); 29 35 } 30 36 37 //--------------------------------------------------------------- 38 31 39 CAttribute * CAttributeMap::operator[](const StdString & key) 32 40 { … … 36 44 return (SuperClassMap::operator[](key)); 37 45 } 38 46 47 //--------------------------------------------------------------- 48 39 49 StdString CAttributeMap::toString(void) const 40 50 { … … 51 61 return (oss.str()); 52 62 } 53 63 64 //--------------------------------------------------------------- 65 54 66 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 //--------------------------------------------------------------- 57 73 58 74 //StdOStream & operator << (StdOStream & os, const CAttributeMap & attributmap) 59 75 //{ os << attributmap.toString(); return (os); } 60 76 77 //--------------------------------------------------------------- 78 61 79 void CAttributeMap::setAttributes(const xml::THashAttributes & attributes) 62 80 { … … 71 89 } 72 90 } 73 91 92 //--------------------------------------------------------------- 93 74 94 void CAttributeMap::setAttributes(const CAttributeMap * const _parent) 75 95 { … … 90 110 } 91 111 } 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 ///-------------------------------------------------------------- 92 173 93 174 } // namespace tree
Note: See TracChangeset
for help on using the changeset viewer.