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