[591] | 1 | #ifndef __XIOS_CAttributeTemplate_impl__ |
---|
| 2 | #define __XIOS_CAttributeTemplate_impl__ |
---|
[219] | 3 | |
---|
[300] | 4 | #include "type.hpp" |
---|
| 5 | #include "buffer_in.hpp" |
---|
| 6 | #include "buffer_out.hpp" |
---|
[352] | 7 | #include "generate_interface.hpp" |
---|
| 8 | #include "attribute_template.hpp" |
---|
[219] | 9 | |
---|
[775] | 10 | |
---|
[335] | 11 | namespace xios |
---|
[219] | 12 | { |
---|
[313] | 13 | |
---|
[219] | 14 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 15 | template <class T> |
---|
| 16 | CAttributeTemplate<T>::CAttributeTemplate(const StdString & id) |
---|
| 17 | : CAttribute(id) |
---|
| 18 | { /* Ne rien faire de plus */ } |
---|
| 19 | |
---|
| 20 | template <class T> |
---|
| 21 | CAttributeTemplate<T>::CAttributeTemplate(const StdString & id, const T & value) |
---|
| 22 | : CAttribute(id) |
---|
| 23 | { |
---|
| 24 | this->setValue(value); |
---|
| 25 | } |
---|
[2019] | 26 | |
---|
[219] | 27 | template <class T> |
---|
| 28 | CAttributeTemplate<T>::CAttributeTemplate(const StdString & id, |
---|
| 29 | xios_map<StdString, CAttribute*> & umap) |
---|
| 30 | : CAttribute(id) |
---|
| 31 | { |
---|
| 32 | umap.insert(umap.end(), std::make_pair(id, this)); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | template <class T> |
---|
| 36 | CAttributeTemplate<T>::CAttributeTemplate |
---|
| 37 | (const StdString & id, const T & value, |
---|
| 38 | xios_map<StdString, CAttribute*> & umap) |
---|
| 39 | : CAttribute(id) |
---|
| 40 | { |
---|
| 41 | this->setValue(value); |
---|
| 42 | umap.insert(umap.end(), std::make_pair(id, this)); |
---|
| 43 | } |
---|
[2019] | 44 | |
---|
[219] | 45 | ///-------------------------------------------------------------- |
---|
[460] | 46 | template <class T> |
---|
| 47 | void CAttributeTemplate<T>::reset(void) |
---|
| 48 | { |
---|
| 49 | CType<T>::reset() ; |
---|
| 50 | inheritedValue.reset() ; |
---|
| 51 | } |
---|
[219] | 52 | |
---|
| 53 | template <class T> |
---|
[1478] | 54 | void CAttributeTemplate<T>::checkEmpty(void) const |
---|
[219] | 55 | { |
---|
[1478] | 56 | if (CType<T>::empty) |
---|
[1477] | 57 | { |
---|
| 58 | StdString msg("On checking attribute with id="); |
---|
| 59 | msg.append(this->getId()); |
---|
| 60 | msg.append(" : "); |
---|
| 61 | msg.append("data is not initialized\n"); |
---|
| 62 | ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << msg); |
---|
| 63 | } |
---|
[1478] | 64 | } |
---|
[1477] | 65 | |
---|
[1478] | 66 | |
---|
| 67 | template <class T> |
---|
| 68 | T CAttributeTemplate<T>::getValue(void) const |
---|
| 69 | { |
---|
| 70 | return CType<T>::get() ; |
---|
[219] | 71 | } |
---|
| 72 | |
---|
[300] | 73 | |
---|
[2019] | 74 | |
---|
[300] | 75 | template <class T> |
---|
[219] | 76 | void CAttributeTemplate<T>::setValue(const T & value) |
---|
| 77 | { |
---|
[369] | 78 | CType<T>::set(value) ; |
---|
[219] | 79 | } |
---|
| 80 | |
---|
[369] | 81 | template <class T> |
---|
| 82 | void CAttributeTemplate<T>::set(const CAttribute& attr) |
---|
| 83 | { |
---|
| 84 | this->set(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ; |
---|
[775] | 85 | } |
---|
[369] | 86 | |
---|
| 87 | template <class T> |
---|
| 88 | void CAttributeTemplate<T>::set(const CAttributeTemplate& attr) |
---|
| 89 | { |
---|
| 90 | CType<T>::set(attr) ; |
---|
[775] | 91 | } |
---|
[369] | 92 | |
---|
[445] | 93 | template <class T> |
---|
| 94 | void CAttributeTemplate<T>::setInheritedValue(const CAttribute& attr) |
---|
| 95 | { |
---|
| 96 | this->setInheritedValue(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ; |
---|
[775] | 97 | } |
---|
[445] | 98 | |
---|
| 99 | template <class T> |
---|
| 100 | void CAttributeTemplate<T>::setInheritedValue(const CAttributeTemplate& attr) |
---|
| 101 | { |
---|
[1158] | 102 | if (this->isEmpty() && _canInherite && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()) ; |
---|
[775] | 103 | } |
---|
[445] | 104 | |
---|
| 105 | template <class T> |
---|
| 106 | T CAttributeTemplate<T>::getInheritedValue(void) const |
---|
| 107 | { |
---|
| 108 | if (this->isEmpty()) return inheritedValue.get() ; |
---|
| 109 | else return getValue() ; |
---|
[775] | 110 | } |
---|
| 111 | |
---|
[445] | 112 | template <class T> |
---|
| 113 | bool CAttributeTemplate<T>::hasInheritedValue(void) const |
---|
| 114 | { |
---|
| 115 | return !this->isEmpty() || !inheritedValue.isEmpty() ; |
---|
[775] | 116 | } |
---|
| 117 | |
---|
[1158] | 118 | template <class T> |
---|
| 119 | bool CAttributeTemplate<T>::isEqual(const CAttribute& attr) |
---|
| 120 | { |
---|
| 121 | const CAttributeTemplate<T>& tmp = dynamic_cast<const CAttributeTemplate<T>& >(attr); |
---|
| 122 | return this->isEqual_(tmp); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | template <class T> |
---|
| 126 | bool CAttributeTemplate<T>::isEqual_(const CAttributeTemplate& attr) |
---|
| 127 | { |
---|
| 128 | if ((!this->hasInheritedValue() && !attr.hasInheritedValue())) |
---|
| 129 | return true; |
---|
| 130 | if (this->hasInheritedValue() && attr.hasInheritedValue()) |
---|
| 131 | return (this->getInheritedValue() == attr.getInheritedValue()); |
---|
| 132 | else |
---|
| 133 | return false; |
---|
| 134 | } |
---|
| 135 | |
---|
[219] | 136 | //--------------------------------------------------------------- |
---|
| 137 | |
---|
| 138 | template <class T> |
---|
[369] | 139 | CAttributeTemplate<T>& CAttributeTemplate<T>::operator=(const T & value) |
---|
[219] | 140 | { |
---|
| 141 | this->setValue(value); |
---|
[369] | 142 | return *this; |
---|
[219] | 143 | } |
---|
| 144 | |
---|
| 145 | //--------------------------------------------------------------- |
---|
| 146 | |
---|
| 147 | template <class T> |
---|
[369] | 148 | StdString CAttributeTemplate<T>::_toString(void) const |
---|
[219] | 149 | { |
---|
| 150 | StdOStringStream oss; |
---|
[369] | 151 | if (!CType<T>::isEmpty() && this->hasId()) |
---|
| 152 | oss << this->getName() << "=\"" << CType<T>::toString() << "\""; |
---|
[219] | 153 | return (oss.str()); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | template <class T> |
---|
[369] | 157 | void CAttributeTemplate<T>::_fromString(const StdString & str) |
---|
[219] | 158 | { |
---|
[369] | 159 | CType<T>::fromString(str) ; |
---|
[219] | 160 | } |
---|
| 161 | |
---|
| 162 | //--------------------------------------------------------------- |
---|
[1612] | 163 | |
---|
| 164 | template <class T> |
---|
| 165 | StdString CAttributeTemplate<T>::_dump(void) const |
---|
| 166 | { |
---|
| 167 | StdOStringStream oss; |
---|
| 168 | if (!CType<T>::isEmpty() && this->hasId()) |
---|
| 169 | oss << this->getName() << "=\"" << CType<T>::dump() << "\""; |
---|
| 170 | return (oss.str()); |
---|
| 171 | } |
---|
[2019] | 172 | |
---|
[1686] | 173 | template <class T> |
---|
[2019] | 174 | StdString CAttributeTemplate<T>::_dumpGraph(void) const |
---|
[1686] | 175 | { |
---|
| 176 | StdOStringStream oss; |
---|
| 177 | if (!CType<T>::isEmpty() && this->hasId()) |
---|
| 178 | oss << this->getName() << "=" << CType<T>::dump() << "</br>"; |
---|
| 179 | return (oss.str()); |
---|
| 180 | } |
---|
[1612] | 181 | |
---|
[1686] | 182 | |
---|
[1612] | 183 | //--------------------------------------------------------------- |
---|
[369] | 184 | /* |
---|
[219] | 185 | template <class T> |
---|
| 186 | void CAttributeTemplate<T>::toBinary (StdOStream & os) const |
---|
| 187 | { |
---|
| 188 | this->getValue()->toBinary(os); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | template <class T> |
---|
| 192 | void CAttributeTemplate<T>::fromBinary(StdIStream & is) |
---|
| 193 | { |
---|
| 194 | T value; |
---|
| 195 | FromBinary(is, value); |
---|
| 196 | this->setValue(value); |
---|
| 197 | } |
---|
[369] | 198 | */ |
---|
[300] | 199 | template <class T> |
---|
[369] | 200 | bool CAttributeTemplate<T>::_toBuffer (CBufferOut& buffer) const |
---|
[300] | 201 | { |
---|
[369] | 202 | return CType<T>::toBuffer(buffer) ; |
---|
[775] | 203 | /* |
---|
[300] | 204 | if (isEmpty()) return buffer.put(true) ; |
---|
| 205 | else |
---|
| 206 | { |
---|
| 207 | bool ret=true ; |
---|
| 208 | CType<T> val(*boost::any_cast<T>(&value)) ; |
---|
| 209 | ret&=buffer.put(false) ; |
---|
| 210 | ret&=val.toBuffer(buffer) ; |
---|
| 211 | return ret ; |
---|
| 212 | } |
---|
[369] | 213 | */ |
---|
[300] | 214 | } |
---|
| 215 | |
---|
| 216 | template <class T> |
---|
[369] | 217 | bool CAttributeTemplate<T>::_fromBuffer(CBufferIn& buffer) |
---|
[300] | 218 | { |
---|
[369] | 219 | return CType<T>::fromBuffer(buffer) ; |
---|
[775] | 220 | /* |
---|
[300] | 221 | bool empty ; |
---|
| 222 | bool ret=true ; |
---|
| 223 | ret&=buffer.get(empty) ; |
---|
[775] | 224 | if (empty) |
---|
[300] | 225 | { |
---|
| 226 | clear() ; |
---|
| 227 | return ret ; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
| 231 | if (isEmpty()) |
---|
| 232 | { |
---|
| 233 | T val ; |
---|
| 234 | setValue(val) ; |
---|
| 235 | } |
---|
| 236 | T* V=const_cast<T*>(boost::any_cast<T>(&value)) ; |
---|
| 237 | CType<T> val(*V) ; |
---|
| 238 | return val.fromBuffer(buffer) ; |
---|
| 239 | } |
---|
[369] | 240 | */ |
---|
[300] | 241 | } |
---|
[369] | 242 | /* |
---|
[300] | 243 | template <class T> |
---|
| 244 | size_t CAttributeTemplate<T>::size(void) const |
---|
[775] | 245 | { |
---|
[369] | 246 | return CType<T>::size() ;*/ |
---|
[775] | 247 | /* |
---|
[300] | 248 | if (isEmpty()) return sizeof(bool) ; |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | CType<T> val(*const_cast<T*>(boost::any_cast<T>(&value))) ; |
---|
| 252 | return val.size()+sizeof(bool) ; |
---|
| 253 | } |
---|
[369] | 254 | */ |
---|
| 255 | /* }*/ |
---|
[300] | 256 | |
---|
[313] | 257 | template <typename T> |
---|
| 258 | void CAttributeTemplate<T>::generateCInterface(ostream& oss,const string& className) |
---|
| 259 | { |
---|
[778] | 260 | CInterface::AttributeCInterface<T>(oss, className, this->getName()); |
---|
[313] | 261 | } |
---|
[775] | 262 | |
---|
[313] | 263 | template <typename T> |
---|
| 264 | void CAttributeTemplate<T>::generateFortran2003Interface(ostream& oss,const string& className) |
---|
| 265 | { |
---|
[778] | 266 | CInterface::AttributeFortran2003Interface<T>(oss, className, this->getName()); |
---|
[313] | 267 | } |
---|
[775] | 268 | |
---|
[313] | 269 | template <typename T> |
---|
| 270 | void CAttributeTemplate<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className) |
---|
| 271 | { |
---|
[778] | 272 | CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName() + "_"); |
---|
[313] | 273 | } |
---|
[775] | 274 | |
---|
[313] | 275 | template <typename T> |
---|
| 276 | void CAttributeTemplate<T>::generateFortranInterfaceBody_(ostream& oss,const string& className) |
---|
| 277 | { |
---|
[778] | 278 | CInterface::AttributeFortranInterfaceBody<T>(oss, className, this->getName()); |
---|
[313] | 279 | } |
---|
| 280 | |
---|
| 281 | template <typename T> |
---|
| 282 | void CAttributeTemplate<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className) |
---|
| 283 | { |
---|
[778] | 284 | CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName()); |
---|
[313] | 285 | } |
---|
[775] | 286 | |
---|
[313] | 287 | template <typename T> |
---|
| 288 | void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) |
---|
| 289 | { |
---|
[778] | 290 | CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName() + "_"); |
---|
[313] | 291 | } |
---|
[775] | 292 | |
---|
| 293 | |
---|
[313] | 294 | template <typename T> |
---|
| 295 | void CAttributeTemplate<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className) |
---|
| 296 | { |
---|
[778] | 297 | CInterface::AttributeFortranInterfaceGetBody<T>(oss, className, this->getName()); |
---|
[313] | 298 | } |
---|
| 299 | |
---|
| 300 | template <typename T> |
---|
| 301 | void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) |
---|
| 302 | { |
---|
[778] | 303 | CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName()); |
---|
[313] | 304 | } |
---|
[432] | 305 | |
---|
[775] | 306 | |
---|
| 307 | /* |
---|
[219] | 308 | //--------------------------------------------------------------- |
---|
| 309 | |
---|
[775] | 310 | // Spécialisations des templates pour la fonction [toString] |
---|
[219] | 311 | |
---|
| 312 | template <> |
---|
| 313 | StdString CAttributeTemplate<bool>::toString(void) const; |
---|
| 314 | |
---|
| 315 | //--------------------------------------------------------------- |
---|
| 316 | |
---|
[775] | 317 | // Spécialisations des templates pour la fonction [fromString] |
---|
[219] | 318 | |
---|
| 319 | template <> // Chaîne de caractÚres. |
---|
| 320 | void CAttributeTemplate<StdString>::fromString(const StdString & str); |
---|
| 321 | |
---|
| 322 | template <> // Entier |
---|
| 323 | void CAttributeTemplate<int>::fromString(const StdString & str); |
---|
| 324 | |
---|
| 325 | template <> // Booléen |
---|
| 326 | void CAttributeTemplate<bool>::fromString(const StdString & str); |
---|
| 327 | |
---|
| 328 | template <> // Double |
---|
| 329 | void CAttributeTemplate<double>::fromString(const StdString & str); |
---|
| 330 | |
---|
| 331 | template<> // Tableau |
---|
| 332 | void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str); |
---|
| 333 | |
---|
| 334 | //--------------------------------------------------------------- |
---|
| 335 | |
---|
[369] | 336 | // Spécialisations des templates pour la fonction [toBinary] // |
---|
[219] | 337 | |
---|
| 338 | template <> // Chaîne de caractÚres. |
---|
| 339 | void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const; |
---|
| 340 | |
---|
| 341 | template <> // Entier |
---|
| 342 | void CAttributeTemplate<int>::toBinary(StdOStream & os) const; |
---|
| 343 | |
---|
| 344 | template <> // Booléen |
---|
| 345 | void CAttributeTemplate<bool>::toBinary(StdOStream & os) const; |
---|
[775] | 346 | |
---|
[219] | 347 | template <> // Double |
---|
| 348 | void CAttributeTemplate<double>::toBinary(StdOStream & os) const; |
---|
| 349 | |
---|
| 350 | //--------------------------------------------------------------- |
---|
| 351 | |
---|
[369] | 352 | // Spécialisations des templates pour la fonction [fromBinary] // |
---|
[219] | 353 | |
---|
| 354 | template <> // Chaîne de caractÚres. |
---|
| 355 | void CAttributeTemplate<StdString>::fromBinary(StdIStream & is); |
---|
| 356 | |
---|
| 357 | template <> // Entier |
---|
| 358 | void CAttributeTemplate<int>::fromBinary(StdIStream & is); |
---|
| 359 | |
---|
| 360 | template <> // Booléen |
---|
| 361 | void CAttributeTemplate<bool>::fromBinary(StdIStream & is); |
---|
[775] | 362 | |
---|
[219] | 363 | template <> // Double |
---|
| 364 | void CAttributeTemplate<double>::fromBinary(StdIStream & is); |
---|
| 365 | |
---|
| 366 | ///-------------------------------------------------------------- |
---|
[775] | 367 | */ |
---|
[335] | 368 | } // namespace xios |
---|
[219] | 369 | |
---|
[591] | 370 | #endif // __XIOS_CAttributeTemplate_impl__ |
---|