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

Last change on this file since 1878 was 1704, checked in by yushan, 5 years ago

Introducing the new graph functionality. Attribute build_workflow_graph=.TRUE. is used in the field definition section in the xml file to enable the workflow graph of the field and other fields referecing to it. A more detailed document will be available soon on the graph fuctionality.

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