source: XIOS/dev/dev_trunk_graph/src/attribute_template_impl.hpp @ 2129

Last change on this file since 2129 was 2019, checked in by yushan, 3 years ago

Graph intermedia commit to a tmp branch

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