source: XIOS/dev/branch_yushan/src/attribute_template_impl.hpp @ 1102

Last change on this file since 1102 was 1102, checked in by yushan, 7 years ago

clean up

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 10.7 KB
RevLine 
[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]11namespace 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      {
[1101]41         xios_map<StdString, CAttribute*>::iterator it;
[1102]42         //printf("umap size = %lu, add = %p\n", umap.size(), &umap);
[1101]43         it = umap.find(id);
44         if(it == umap.end())
45           umap.insert(umap.end(), std::make_pair(id, this));
[219]46      }
47
48      template <class T>
49         CAttributeTemplate<T>::CAttributeTemplate
50            (const StdString & id, const T & value,
51             xios_map<StdString, CAttribute*> & umap)
52         : CAttribute(id)
53      {
54         this->setValue(value);
55         umap.insert(umap.end(), std::make_pair(id, this));
56      }
[369]57/*
[219]58      template <class T>
[369]59      CAttributeTemplate<T>::~CAttributeTemplate(void)
[775]60      {
[369]61//         this->CType<T>::reset() ;
62//         this->clear();
[219]63      }
[369]64*/
[219]65      ///--------------------------------------------------------------
[460]66      template <class T>
67      void CAttributeTemplate<T>::reset(void)
68      {
69        CType<T>::reset() ;
70        inheritedValue.reset() ;
71      }
[219]72
[460]73
[219]74      template <class T>
75         T CAttributeTemplate<T>::getValue(void) const
76      {
[1037]77         return CType<T>::get() ;
[369]78/*
[1037]79         if (SuperClass::isEmpty())
80         {
81            ERROR("T CAttributeTemplate<T>::getValue(void) const",
82                  << "[ id = " << this->getId() << "]"
83                  << " L'attribut est requis mais n'est pas défini !");
84          }
85         return (SuperClass::getValue<T>());
[369]86*/
[219]87      }
88
[369]89/*
[219]90      template <class T>
[300]91         T* CAttributeTemplate<T>::getRef(void)
92      {
93         if (SuperClass::isEmpty())
94         {
95            ERROR("T CAttributeTemplate<T>::getValue(void) const",
96                  << "[ id = " << this->getId() << "]"
97                  << " L'attribut est requis mais n'est pas défini !");
98          }
99         return (SuperClass::getRef<T>());
100      }
[369]101*/
[300]102
103      template <class T>
[219]104         void CAttributeTemplate<T>::setValue(const T & value)
105      {
[369]106         CType<T>::set(value) ;
107//         SuperClass::setValue<T>(value);
[219]108      }
109
[369]110    template <class T>
111    void CAttributeTemplate<T>::set(const CAttribute& attr)
112    {
113      this->set(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ;
[775]114    }
[369]115
116   template <class T>
117    void CAttributeTemplate<T>::set(const CAttributeTemplate& attr)
118    {
119      CType<T>::set(attr) ;
[775]120    }
[369]121
[445]122    template <class T>
123    void CAttributeTemplate<T>::setInheritedValue(const CAttribute& attr)
124    {
125      this->setInheritedValue(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ;
[775]126    }
[445]127
128    template <class T>
129    void CAttributeTemplate<T>::setInheritedValue(const CAttributeTemplate& attr)
130    {
131      if (this->isEmpty() && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()) ;
[775]132    }
[445]133
134    template <class T>
135    T CAttributeTemplate<T>::getInheritedValue(void) const
136    {
137      if (this->isEmpty()) return inheritedValue.get() ;
138      else return getValue() ;
[775]139    }
140
[445]141    template <class T>
142    bool CAttributeTemplate<T>::hasInheritedValue(void) const
143    {
144      return !this->isEmpty() || !inheritedValue.isEmpty() ;
[775]145    }
146
[219]147      //---------------------------------------------------------------
148
149      template <class T>
[369]150         CAttributeTemplate<T>& CAttributeTemplate<T>::operator=(const T & value)
[219]151      {
152         this->setValue(value);
[369]153//         return (this->getValue());
154         return *this;
[219]155      }
156
157      //---------------------------------------------------------------
158
159      template <class T>
[369]160         StdString CAttributeTemplate<T>::_toString(void) const
[219]161      {
162         StdOStringStream oss;
[369]163         if (!CType<T>::isEmpty() && this->hasId())
164            oss << this->getName() << "=\"" << CType<T>::toString() << "\"";
[219]165         return (oss.str());
166      }
167
168      template <class T>
[369]169         void CAttributeTemplate<T>::_fromString(const StdString & str)
[219]170      {
[369]171        CType<T>::fromString(str) ;
[219]172      }
173
174      //---------------------------------------------------------------
[369]175/*
[219]176      template <class T>
177         void CAttributeTemplate<T>::toBinary (StdOStream & os) const
178      {
179         this->getValue()->toBinary(os);
180      }
181
182      template <class T>
183         void CAttributeTemplate<T>::fromBinary(StdIStream & is)
184      {
185         T value;
186         FromBinary(is, value);
187         this->setValue(value);
188      }
[369]189*/
[300]190      template <class T>
[369]191         bool CAttributeTemplate<T>::_toBuffer (CBufferOut& buffer) const
[300]192      {
[369]193         return CType<T>::toBuffer(buffer) ;
[775]194/*
[300]195         if (isEmpty()) return buffer.put(true) ;
196         else
197         {
198           bool ret=true ;
199           CType<T> val(*boost::any_cast<T>(&value)) ;
200           ret&=buffer.put(false) ;
201           ret&=val.toBuffer(buffer) ;
202           return ret ;
203         }
[369]204*/
[300]205      }
206
207      template <class T>
[369]208      bool CAttributeTemplate<T>::_fromBuffer(CBufferIn& buffer)
[300]209      {
[369]210        return CType<T>::fromBuffer(buffer) ;
[775]211/*
[300]212        bool empty ;
213        bool ret=true ;
214        ret&=buffer.get(empty) ;
[775]215        if (empty)
[300]216        {
217          clear() ;
218          return ret ;
219        }
220        else
221        {
222          if (isEmpty())
223          {
224            T val ;
225            setValue(val) ;
226          }
227          T* V=const_cast<T*>(boost::any_cast<T>(&value)) ;
228          CType<T> val(*V) ;
229          return val.fromBuffer(buffer) ;
230        }
[369]231*/
[300]232      }
[369]233/*
[300]234      template <class T>
235      size_t CAttributeTemplate<T>::size(void) const
[775]236      {
[369]237        return CType<T>::size() ;*/
[775]238/*
[300]239        if (isEmpty()) return sizeof(bool) ;
240        else
241        {
242          CType<T> val(*const_cast<T*>(boost::any_cast<T>(&value))) ;
243          return val.size()+sizeof(bool) ;
244        }
[369]245*/
246 /*     }*/
[300]247
[313]248      template <typename T>
249      void CAttributeTemplate<T>::generateCInterface(ostream& oss,const string& className)
250      {
[778]251        CInterface::AttributeCInterface<T>(oss, className, this->getName());
[313]252      }
[775]253
[313]254      template <typename T>
255      void CAttributeTemplate<T>::generateFortran2003Interface(ostream& oss,const string& className)
256      {
[778]257        CInterface::AttributeFortran2003Interface<T>(oss, className, this->getName());
[313]258      }
[775]259
[313]260      template <typename T>
261      void CAttributeTemplate<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className)
262      {
[778]263        CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName() + "_");
[313]264      }
[775]265
[313]266      template <typename T>
267      void CAttributeTemplate<T>::generateFortranInterfaceBody_(ostream& oss,const string& className)
268      {
[778]269        CInterface::AttributeFortranInterfaceBody<T>(oss, className, this->getName());
[313]270      }
271
272      template <typename T>
273      void CAttributeTemplate<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className)
274      {
[778]275        CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName());
[313]276      }
[775]277
[313]278      template <typename T>
279      void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className)
280      {
[778]281        CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName() + "_");
[313]282      }
[775]283
284
[313]285      template <typename T>
286      void CAttributeTemplate<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className)
287      {
[778]288        CInterface::AttributeFortranInterfaceGetBody<T>(oss, className, this->getName());
[313]289      }
290
291      template <typename T>
292      void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className)
293      {
[778]294        CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName());
[313]295      }
[432]296
[775]297
298/*
[219]299      //---------------------------------------------------------------
300
[775]301      // Spécialisations des templates pour la fonction [toString]
[219]302
303      template <>
304         StdString CAttributeTemplate<bool>::toString(void) const;
305
306      //---------------------------------------------------------------
307
[775]308      // Spécialisations des templates pour la fonction [fromString]
[219]309
310      template <> // Chaîne de caractÚres.
311         void CAttributeTemplate<StdString>::fromString(const StdString & str);
312
313      template <> // Entier
314         void CAttributeTemplate<int>::fromString(const StdString & str);
315
316      template <> // Booléen
317         void CAttributeTemplate<bool>::fromString(const StdString & str);
318
319      template <> // Double
320         void CAttributeTemplate<double>::fromString(const StdString & str);
321
322      template<> // Tableau
323         void CAttributeTemplate<ARRAY(double, 1)>::fromString(const StdString & str);
324
325      //---------------------------------------------------------------
326
[369]327      // Spécialisations des templates pour la fonction [toBinary] //
[219]328
329      template <> // Chaîne de caractÚres.
330         void CAttributeTemplate<StdString>::toBinary (StdOStream & os) const;
331
332      template <> // Entier
333         void CAttributeTemplate<int>::toBinary(StdOStream & os) const;
334
335      template <> // Booléen
336         void CAttributeTemplate<bool>::toBinary(StdOStream & os) const;
[775]337
[219]338      template <> // Double
339         void CAttributeTemplate<double>::toBinary(StdOStream & os) const;
340
341      //---------------------------------------------------------------
342
[369]343      // Spécialisations des templates pour la fonction [fromBinary] //
[219]344
345      template <> // Chaîne de caractÚres.
346         void CAttributeTemplate<StdString>::fromBinary(StdIStream & is);
347
348      template <> // Entier
349         void CAttributeTemplate<int>::fromBinary(StdIStream & is);
350
351      template <> // Booléen
352         void CAttributeTemplate<bool>::fromBinary(StdIStream & is);
[775]353
[219]354      template <> // Double
355         void CAttributeTemplate<double>::fromBinary(StdIStream & is);
356
357      ///--------------------------------------------------------------
[775]358*/
[335]359} // namespace xios
[219]360
[591]361#endif // __XIOS_CAttributeTemplate_impl__
Note: See TracBrowser for help on using the repository browser.