source: XIOS/trunk/src/attribute_enum_impl.hpp @ 459

Last change on this file since 459 was 445, checked in by ymipsl, 11 years ago

Add possibility to make inheritance of attributes and reference before closing the context definition.
New fortran fonction : xios_solve inheritance()
After this call, the value of attribute have the inherited value of their parent.

YM

File size: 6.0 KB
Line 
1#ifndef __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__
2#define __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__
3
4#include "enum.hpp"
5#include "buffer_in.hpp"
6#include "buffer_out.hpp"
7#include "generate_interface.hpp"
8#include "attribute_enum.hpp"
9
10 
11namespace xios
12{
13
14      /// ////////////////////// Définitions ////////////////////// ///
15      template <class T>
16         CAttributeEnum<T>::CAttributeEnum(const StdString & id)
17         : CAttribute(id)
18      { /* Ne rien faire de plus */ }
19
20      template <class T>
21         CAttributeEnum<T>::CAttributeEnum(const StdString & id, const T_enum & value)
22         : CAttribute(id)
23      {
24         this->setValue(value);
25      }
26
27      template <class T>
28      CAttributeEnum<T>::CAttributeEnum(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         CAttributeEnum<T>::CAttributeEnum
37            (const StdString & id, const T_enum & 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
47      template <class T>
48      typename T::t_enum CAttributeEnum<T>::getValue(void) const
49      {
50         return CEnum<T>::get() ;
51      }
52
53      template <class T>
54         string CAttributeEnum<T>::getStringValue(void) const
55      {
56         return CEnum<T>::toString() ;
57      }
58
59      template <class T>
60         void CAttributeEnum<T>::setValue(const typename T::t_enum & value)
61      {
62         CEnum<T>::set(value) ;
63      }
64
65    template <class T>
66    void CAttributeEnum<T>::set(const CAttribute& attr)
67    {
68      this->set(dynamic_cast<const CAttributeEnum<T>& >(attr)) ;
69    } 
70
71   template <class T>
72    void CAttributeEnum<T>::set(const CAttributeEnum& attr)
73    {
74      CEnum<T>::set(attr) ;
75    } 
76
77   
78    template <class T>
79    void CAttributeEnum<T>::setInheritedValue(const CAttribute& attr)
80    {
81      this->setInheritedValue(dynamic_cast<const CAttributeEnum<T>& >(attr)) ;
82    } 
83
84    template <class T>
85    void CAttributeEnum<T>::setInheritedValue(const CAttributeEnum& attr)
86    {
87      if (this->isEmpty() && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue()) ;
88    } 
89
90    template <class T>
91    typename T::t_enum CAttributeEnum<T>::getInheritedValue(void) const
92    {
93      if (this->isEmpty()) return inheritedValue.get() ;
94      else return getValue() ;
95    } 
96   
97    template <class T>
98    string CAttributeEnum<T>::getInheritedStringValue(void) const
99    {
100       return CEnum<T>::toString() ;
101       if (this->isEmpty()) return inheritedValue.toString() ;
102       else return CEnum<T>::toString() ; ;
103    }
104   
105    template <class T>
106    bool CAttributeEnum<T>::hasInheritedValue(void) const
107    {
108      return !this->isEmpty() || !inheritedValue.isEmpty() ;
109    } 
110   
111      //---------------------------------------------------------------
112
113      template <class T>
114      CAttributeEnum<T>& CAttributeEnum<T>::operator=(const T_enum & value)
115      {
116         this->setValue(value);
117         return *this;
118      }
119
120      //---------------------------------------------------------------
121
122      template <class T>
123         StdString CAttributeEnum<T>::_toString(void) const
124      {
125         StdOStringStream oss;
126         if (!CEnum<T>::isEmpty() && this->hasId())
127            oss << this->getName() << "=\"" << CEnum<T>::toString() << "\"";
128         return (oss.str());
129      }
130
131      template <class T>
132         void CAttributeEnum<T>::_fromString(const StdString & str)
133      {
134        CEnum<T>::fromString(str) ;
135      }
136
137      template <class T>
138      bool CAttributeEnum<T>::_toBuffer (CBufferOut& buffer) const
139      {
140         return CEnum<T>::toBuffer(buffer) ;
141      }
142
143      template <class T>
144      bool CAttributeEnum<T>::_fromBuffer(CBufferIn& buffer)
145      {
146        return CEnum<T>::fromBuffer(buffer) ;
147      }
148
149      template <typename T>
150      void CAttributeEnum<T>::generateCInterface(ostream& oss,const string& className)
151      {
152        CInterface::AttributeCInterface<CEnumBase>(oss, className, this->getName()) ;
153      }
154     
155      template <typename T>
156      void CAttributeEnum<T>::generateFortran2003Interface(ostream& oss,const string& className)
157      {
158        CInterface::AttributeFortran2003Interface<string>(oss, className, this->getName()) ;
159      }
160     
161      template <typename T>
162      void CAttributeEnum<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className)
163      {
164        CInterface::AttributeFortranInterfaceDeclaration<string>(oss, className, this->getName()+"_") ;
165      }
166 
167      template <typename T>
168      void CAttributeEnum<T>::generateFortranInterfaceBody_(ostream& oss,const string& className)
169      {
170        CInterface::AttributeFortranInterfaceBody<string>(oss, className, this->getName()) ;
171      }
172
173      template <typename T>
174      void CAttributeEnum<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className)
175      {
176        CInterface::AttributeFortranInterfaceDeclaration<string>(oss, className, this->getName()) ;
177      }
178     
179      template <typename T>
180      void CAttributeEnum<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className)
181      {
182        CInterface::AttributeFortranInterfaceGetDeclaration<string>(oss, className, this->getName()+"_") ;
183      }
184 
185      template <typename T>
186      void CAttributeEnum<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className)
187      {
188        CInterface::AttributeFortranInterfaceGetBody<string>(oss, className, this->getName()) ;
189      }
190
191      template <typename T>
192      void CAttributeEnum<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className)
193      {
194        CInterface::AttributeFortranInterfaceGetDeclaration<string>(oss, className, this->getName()) ;
195      }
196 
197} // namespace xios
198
199#endif // __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__
Note: See TracBrowser for help on using the repository browser.