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