source: XIOS/trunk/src/attribute_template_impl.hpp @ 1117

Last change on this file since 1117 was 1117, checked in by mhnguyen, 7 years ago

Fixing bug of using *_ref on chaining transformations.

+) Correct isEqual function of attribute_template
+) Modify isEqual function of CAttributeMap to make sure that some attributes are
excluded from comparasion

Test
+) On Curie
+) toy_cmpi6 works.

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