[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 | |
---|
[219] | 111 | //--------------------------------------------------------------- |
---|
| 112 | |
---|
| 113 | template <class T> |
---|
[369] | 114 | CAttributeTemplate<T>& CAttributeTemplate<T>::operator=(const T & value) |
---|
[219] | 115 | { |
---|
| 116 | this->setValue(value); |
---|
[369] | 117 | // return (this->getValue()); |
---|
| 118 | return *this; |
---|
[219] | 119 | } |
---|
| 120 | |
---|
| 121 | //--------------------------------------------------------------- |
---|
| 122 | |
---|
| 123 | template <class T> |
---|
[369] | 124 | StdString CAttributeTemplate<T>::_toString(void) const |
---|
[219] | 125 | { |
---|
| 126 | StdOStringStream oss; |
---|
[369] | 127 | if (!CType<T>::isEmpty() && this->hasId()) |
---|
| 128 | oss << this->getName() << "=\"" << CType<T>::toString() << "\""; |
---|
[219] | 129 | return (oss.str()); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | template <class T> |
---|
[369] | 133 | void CAttributeTemplate<T>::_fromString(const StdString & str) |
---|
[219] | 134 | { |
---|
[369] | 135 | CType<T>::fromString(str) ; |
---|
[219] | 136 | } |
---|
| 137 | |
---|
| 138 | //--------------------------------------------------------------- |
---|
[369] | 139 | /* |
---|
[219] | 140 | template <class T> |
---|
| 141 | void CAttributeTemplate<T>::toBinary (StdOStream & os) const |
---|
| 142 | { |
---|
| 143 | this->getValue()->toBinary(os); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | template <class T> |
---|
| 147 | void CAttributeTemplate<T>::fromBinary(StdIStream & is) |
---|
| 148 | { |
---|
| 149 | T value; |
---|
| 150 | FromBinary(is, value); |
---|
| 151 | this->setValue(value); |
---|
| 152 | } |
---|
[369] | 153 | */ |
---|
[300] | 154 | template <class T> |
---|
[369] | 155 | bool CAttributeTemplate<T>::_toBuffer (CBufferOut& buffer) const |
---|
[300] | 156 | { |
---|
[369] | 157 | return CType<T>::toBuffer(buffer) ; |
---|
| 158 | /* |
---|
[300] | 159 | if (isEmpty()) return buffer.put(true) ; |
---|
| 160 | else |
---|
| 161 | { |
---|
| 162 | bool ret=true ; |
---|
| 163 | CType<T> val(*boost::any_cast<T>(&value)) ; |
---|
| 164 | ret&=buffer.put(false) ; |
---|
| 165 | ret&=val.toBuffer(buffer) ; |
---|
| 166 | return ret ; |
---|
| 167 | } |
---|
[369] | 168 | */ |
---|
[300] | 169 | } |
---|
| 170 | |
---|
| 171 | template <class T> |
---|
[369] | 172 | bool CAttributeTemplate<T>::_fromBuffer(CBufferIn& buffer) |
---|
[300] | 173 | { |
---|
[369] | 174 | return CType<T>::fromBuffer(buffer) ; |
---|
| 175 | /* |
---|
[300] | 176 | bool empty ; |
---|
| 177 | bool ret=true ; |
---|
| 178 | ret&=buffer.get(empty) ; |
---|
| 179 | if (empty) |
---|
| 180 | { |
---|
| 181 | clear() ; |
---|
| 182 | return ret ; |
---|
| 183 | } |
---|
| 184 | else |
---|
| 185 | { |
---|
| 186 | if (isEmpty()) |
---|
| 187 | { |
---|
| 188 | T val ; |
---|
| 189 | setValue(val) ; |
---|
| 190 | } |
---|
| 191 | T* V=const_cast<T*>(boost::any_cast<T>(&value)) ; |
---|
| 192 | CType<T> val(*V) ; |
---|
| 193 | return val.fromBuffer(buffer) ; |
---|
| 194 | } |
---|
[369] | 195 | */ |
---|
[300] | 196 | } |
---|
[369] | 197 | /* |
---|
[300] | 198 | template <class T> |
---|
| 199 | size_t CAttributeTemplate<T>::size(void) const |
---|
[369] | 200 | { |
---|
| 201 | return CType<T>::size() ;*/ |
---|
| 202 | /* |
---|
[300] | 203 | if (isEmpty()) return sizeof(bool) ; |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | CType<T> val(*const_cast<T*>(boost::any_cast<T>(&value))) ; |
---|
| 207 | return val.size()+sizeof(bool) ; |
---|
| 208 | } |
---|
[369] | 209 | */ |
---|
| 210 | /* }*/ |
---|
[300] | 211 | |
---|
[313] | 212 | template <typename T> |
---|
| 213 | void CAttributeTemplate<T>::generateCInterface(ostream& oss,const string& className) |
---|
| 214 | { |
---|
| 215 | CInterface::AttributeCInterface<T>(oss, className, this->getName()) ; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | template <typename T> |
---|
| 219 | void CAttributeTemplate<T>::generateFortran2003Interface(ostream& oss,const string& className) |
---|
| 220 | { |
---|
| 221 | CInterface::AttributeFortran2003Interface<T>(oss, className, this->getName()) ; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | template <typename T> |
---|
| 225 | void CAttributeTemplate<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className) |
---|
| 226 | { |
---|
| 227 | CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName()+"_") ; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | template <typename T> |
---|
| 231 | void CAttributeTemplate<T>::generateFortranInterfaceBody_(ostream& oss,const string& className) |
---|
| 232 | { |
---|
| 233 | CInterface::AttributeFortranInterfaceBody<T>(oss, className, this->getName()) ; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | template <typename T> |
---|
| 237 | void CAttributeTemplate<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className) |
---|
| 238 | { |
---|
| 239 | CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName()) ; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | template <typename T> |
---|
| 243 | void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) |
---|
| 244 | { |
---|
| 245 | CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName()+"_") ; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | template <typename T> |
---|
| 249 | void CAttributeTemplate<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className) |
---|
| 250 | { |
---|
| 251 | CInterface::AttributeFortranInterfaceGetBody<T>(oss, className, this->getName()) ; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | template <typename T> |
---|
| 255 | void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) |
---|
| 256 | { |
---|
| 257 | CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName()) ; |
---|
| 258 | } |
---|
| 259 | |
---|
[369] | 260 | /* |
---|
[219] | 261 | //--------------------------------------------------------------- |
---|
| 262 | |
---|
[369] | 263 | // Spécialisations des templates pour la fonction [toString] |
---|
[219] | 264 | |
---|
| 265 | template <> |
---|
| 266 | StdString CAttributeTemplate<bool>::toString(void) const; |
---|
| 267 | |
---|
| 268 | //--------------------------------------------------------------- |
---|
| 269 | |
---|
[369] | 270 | // Spécialisations des templates pour la fonction [fromString] |
---|
[219] | 271 | |
---|
| 272 | template <> // Chaîne de caractÚres. |
---|
| 273 | void CAttributeTemplate<StdString>::fromString(const StdString & str); |
---|
| 274 | |
---|
| 275 | template <> // Entier |
---|
| 276 | void CAttributeTemplate<int>::fromString(const StdString & str); |
---|
| 277 | |
---|
| 278 | template <> // Booléen |
---|
| 279 | void CAttributeTemplate<bool>::fromString(const StdString & str); |
---|
| 280 | |
---|
| 281 | template <> // Double |
---|
| 282 | void CAttributeTemplate<double>::fromString(const StdString & str); |
---|
| 283 | |
---|
| 284 | template<> // Tableau |
---|
| 285 | void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str); |
---|
| 286 | |
---|
| 287 | //--------------------------------------------------------------- |
---|
| 288 | |
---|
[369] | 289 | // Spécialisations des templates pour la fonction [toBinary] // |
---|
[219] | 290 | |
---|
| 291 | template <> // Chaîne de caractÚres. |
---|
| 292 | void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const; |
---|
| 293 | |
---|
| 294 | template <> // Entier |
---|
| 295 | void CAttributeTemplate<int>::toBinary(StdOStream & os) const; |
---|
| 296 | |
---|
| 297 | template <> // Booléen |
---|
| 298 | void CAttributeTemplate<bool>::toBinary(StdOStream & os) const; |
---|
| 299 | |
---|
| 300 | template <> // Double |
---|
| 301 | void CAttributeTemplate<double>::toBinary(StdOStream & os) const; |
---|
| 302 | |
---|
| 303 | //--------------------------------------------------------------- |
---|
| 304 | |
---|
[369] | 305 | // Spécialisations des templates pour la fonction [fromBinary] // |
---|
[219] | 306 | |
---|
| 307 | template <> // Chaîne de caractÚres. |
---|
| 308 | void CAttributeTemplate<StdString>::fromBinary(StdIStream & is); |
---|
| 309 | |
---|
| 310 | template <> // Entier |
---|
| 311 | void CAttributeTemplate<int>::fromBinary(StdIStream & is); |
---|
| 312 | |
---|
| 313 | template <> // Booléen |
---|
| 314 | void CAttributeTemplate<bool>::fromBinary(StdIStream & is); |
---|
| 315 | |
---|
| 316 | template <> // Double |
---|
| 317 | void CAttributeTemplate<double>::fromBinary(StdIStream & is); |
---|
| 318 | |
---|
| 319 | ///-------------------------------------------------------------- |
---|
[369] | 320 | */ |
---|
[335] | 321 | } // namespace xios |
---|
[219] | 322 | |
---|
| 323 | #endif // __XMLIO_CAttributeTemplate_impl__ |
---|