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