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
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 CAttribute & attribut)
29         throw (CException)
30         : CAttribute(attribut)
31      {
32         if (!attribut.isEmpty() && !attribut.isType<T>())
33            ERROR("CAttributeTemplate", << "Invalid instantiation !");
34      }
35*/
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      }
53/*
54      template <class T>
55      CAttributeTemplate<T>::~CAttributeTemplate(void)
56      {
57//         this->CType<T>::reset() ;
58//         this->clear();
59      }
60*/
61      ///--------------------------------------------------------------
62      template <class T>
63      void CAttributeTemplate<T>::reset(void)
64      {
65        CType<T>::reset() ;
66        inheritedValue.reset() ;
67      }
68
69
70      template <class T>
71      void CAttributeTemplate<T>::checkEmpty(void) const
72      {
73        if (CType<T>::empty)
74        {
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        }
81      }
82     
83      template <class T>
84      T CAttributeTemplate<T>::getValue(void) const
85      {
86        return CType<T>::get() ;
87      }
88
89
90
91      template <class T>
92      void CAttributeTemplate<T>::setValue(const T & value)
93      {
94         CType<T>::set(value) ;
95//         SuperClass::setValue<T>(value);
96      }
97
98    template <class T>
99    void CAttributeTemplate<T>::set(const CAttribute& attr)
100    {
101      this->set(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ;
102    }
103
104   template <class T>
105    void CAttributeTemplate<T>::set(const CAttributeTemplate& attr)
106    {
107      CType<T>::set(attr) ;
108    }
109
110    template <class T>
111    void CAttributeTemplate<T>::setInheritedValue(const CAttribute& attr)
112    {
113      this->setInheritedValue(dynamic_cast<const CAttributeTemplate<T>& >(attr)) ;
114    }
115
116    template <class T>
117    void CAttributeTemplate<T>::setInheritedValue(const CAttributeTemplate& attr)
118    {
119      if (this->isEmpty() && _canInherite && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()) ;
120    }
121
122    template <class T>
123    T CAttributeTemplate<T>::getInheritedValue(void) const
124    {
125      if (this->isEmpty()) return inheritedValue.get() ;
126      else return getValue() ;
127    }
128
129    template <class T>
130    bool CAttributeTemplate<T>::hasInheritedValue(void) const
131    {
132      return !this->isEmpty() || !inheritedValue.isEmpty() ;
133    }
134
135    template <class T>
136    bool CAttributeTemplate<T>::isEqual(const CAttribute& attr)
137    {
138      const CAttributeTemplate<T>& tmp = dynamic_cast<const CAttributeTemplate<T>& >(attr);
139      return this->isEqual_(tmp);
140    }
141
142    template <class T>
143    bool CAttributeTemplate<T>::isEqual_(const CAttributeTemplate& attr)
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
153      //---------------------------------------------------------------
154
155      template <class T>
156         CAttributeTemplate<T>& CAttributeTemplate<T>::operator=(const T & value)
157      {
158         this->setValue(value);
159//         return (this->getValue());
160         return *this;
161      }
162
163      //---------------------------------------------------------------
164
165      template <class T>
166         StdString CAttributeTemplate<T>::_toString(void) const
167      {
168         StdOStringStream oss;
169         if (!CType<T>::isEmpty() && this->hasId())
170            oss << this->getName() << "=\"" << CType<T>::toString() << "\"";
171         return (oss.str());
172      }
173
174      template <class T>
175         void CAttributeTemplate<T>::_fromString(const StdString & str)
176      {
177        CType<T>::fromString(str) ;
178      }
179
180      //---------------------------------------------------------------
181/*
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      }
195*/
196      template <class T>
197         bool CAttributeTemplate<T>::_toBuffer (CBufferOut& buffer) const
198      {
199         return CType<T>::toBuffer(buffer) ;
200/*
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         }
210*/
211      }
212
213      template <class T>
214      bool CAttributeTemplate<T>::_fromBuffer(CBufferIn& buffer)
215      {
216        return CType<T>::fromBuffer(buffer) ;
217/*
218        bool empty ;
219        bool ret=true ;
220        ret&=buffer.get(empty) ;
221        if (empty)
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        }
237*/
238      }
239/*
240      template <class T>
241      size_t CAttributeTemplate<T>::size(void) const
242      {
243        return CType<T>::size() ;*/
244/*
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        }
251*/
252 /*     }*/
253
254      template <typename T>
255      void CAttributeTemplate<T>::generateCInterface(ostream& oss,const string& className)
256      {
257        CInterface::AttributeCInterface<T>(oss, className, this->getName());
258      }
259
260      template <typename T>
261      void CAttributeTemplate<T>::generateFortran2003Interface(ostream& oss,const string& className)
262      {
263        CInterface::AttributeFortran2003Interface<T>(oss, className, this->getName());
264      }
265
266      template <typename T>
267      void CAttributeTemplate<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className)
268      {
269        CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName() + "_");
270      }
271
272      template <typename T>
273      void CAttributeTemplate<T>::generateFortranInterfaceBody_(ostream& oss,const string& className)
274      {
275        CInterface::AttributeFortranInterfaceBody<T>(oss, className, this->getName());
276      }
277
278      template <typename T>
279      void CAttributeTemplate<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className)
280      {
281        CInterface::AttributeFortranInterfaceDeclaration<T>(oss, className, this->getName());
282      }
283
284      template <typename T>
285      void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className)
286      {
287        CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName() + "_");
288      }
289
290
291      template <typename T>
292      void CAttributeTemplate<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className)
293      {
294        CInterface::AttributeFortranInterfaceGetBody<T>(oss, className, this->getName());
295      }
296
297      template <typename T>
298      void CAttributeTemplate<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className)
299      {
300        CInterface::AttributeFortranInterfaceGetDeclaration<T>(oss, className, this->getName());
301      }
302
303
304/*
305      //---------------------------------------------------------------
306
307      // Spécialisations des templates pour la fonction [toString]
308
309      template <>
310         StdString CAttributeTemplate<bool>::toString(void) const;
311
312      //---------------------------------------------------------------
313
314      // Spécialisations des templates pour la fonction [fromString]
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
333      // Spécialisations des templates pour la fonction [toBinary] //
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;
343
344      template <> // Double
345         void CAttributeTemplate<double>::toBinary(StdOStream & os) const;
346
347      //---------------------------------------------------------------
348
349      // Spécialisations des templates pour la fonction [fromBinary] //
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);
359
360      template <> // Double
361         void CAttributeTemplate<double>::fromBinary(StdIStream & is);
362
363      ///--------------------------------------------------------------
364*/
365} // namespace xios
366
367#endif // __XIOS_CAttributeTemplate_impl__
Note: See TracBrowser for help on using the repository browser.