source: XIOS/dev/branch_openmp/src/attribute_template_impl.hpp @ 1482

Last change on this file since 1482 was 1482, checked in by yushan, 6 years ago

Branch EP merged with Dev_cmip6 @r1481

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