source: XIOS3/trunk/src/attribute_enum_impl.hpp @ 2386

Last change on this file since 2386 was 2386, checked in by jderouillat, 2 years ago

Set the code structure to compute the hash value of an element based on its attributs, use for now before writing an element in a file

  • 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: 6.3 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
10namespace xios
11{
12  /// ////////////////////// Définitions ////////////////////// ///
13  template <class T>
14  CAttributeEnum<T>::CAttributeEnum(const StdString & id)
15     : CAttribute(id)
16  { /* Ne rien faire de plus */ }
17
18  template <class T>
19  CAttributeEnum<T>::CAttributeEnum(const StdString & id, const T_enum & value)
20     : CAttribute(id)
21  {
22     this->setValue(value);
23  }
24
25  template <class T>
26  CAttributeEnum<T>::CAttributeEnum(const StdString & id,
27                                    xios_map<StdString, CAttribute*> & umap)
28     : CAttribute(id)
29  {
30     umap.insert(umap.end(), std::make_pair(id, this));
31  }
32
33  template <class T>
34  CAttributeEnum<T>::CAttributeEnum
35        (const StdString & id, const T_enum & value,
36         xios_map<StdString, CAttribute*> & umap)
37     : CAttribute(id)
38  {
39     this->setValue(value);
40     umap.insert(umap.end(), std::make_pair(id, this));
41  }
42
43  ///--------------------------------------------------------------
44  template <class T>
45  void CAttributeEnum<T>::reset(void)
46  {
47     CEnum<T>::reset();
48     inheritedValue.reset();
49  }
50
51  template <class T>
52  typename T::t_enum CAttributeEnum<T>::getValue(void) const
53  {
54     return CEnum<T>::get();
55  }
56
57  template <class T>
58  string CAttributeEnum<T>::getStringValue(void) const
59  {
60     return CEnum<T>::toString();
61  }
62
63  template <class T>
64  void CAttributeEnum<T>::setValue(const typename T::t_enum & value)
65  {
66     CEnum<T>::set(value);
67  }
68
69  template <class T>
70  void CAttributeEnum<T>::set(const CAttribute& attr)
71  {
72    this->set(dynamic_cast<const CAttributeEnum<T>& >(attr));
73  }
74
75 template <class T>
76  void CAttributeEnum<T>::set(const CAttributeEnum& attr)
77  {
78    CEnum<T>::set(attr);
79  }
80
81  template <class T>
82  void CAttributeEnum<T>::setInheritedValue(const CAttribute& attr)
83  {
84    this->setInheritedValue(dynamic_cast<const CAttributeEnum<T>& >(attr));
85  }
86
87  template <class T>
88  void CAttributeEnum<T>::setInheritedValue(const CAttributeEnum& attr)
89  {
90    if (this->isEmpty() && _canInherite && attr.hasInheritedValue()) inheritedValue.set(attr.getInheritedValue());
91  }
92
93  template <class T>
94  typename T::t_enum CAttributeEnum<T>::getInheritedValue(void) const
95  {
96    if (this->isEmpty()) return inheritedValue.get();
97    else return getValue();
98  }
99
100  template <class T>
101  string CAttributeEnum<T>::getInheritedStringValue(void) const
102  {
103     if (this->isEmpty()) return inheritedValue.toString();
104     else return CEnum<T>::toString();;
105  }
106
107  template <class T>
108  bool CAttributeEnum<T>::hasInheritedValue(void) const
109  {
110    return !this->isEmpty() || !inheritedValue.isEmpty();
111  }
112
113  template <class T>
114  bool CAttributeEnum<T>::isEqual(const CAttribute& attr)
115  {
116    const CAttributeEnum<T>& tmp = dynamic_cast<const CAttributeEnum<T>& >(attr);
117    return this->isEqual_(tmp);
118  }
119
120  template <class T>
121  bool CAttributeEnum<T>::isEqual_(const CAttributeEnum& attr)
122  {
123    if (this->isEmpty() && attr.isEmpty()) return true ;
124    if (!this->isEmpty() && !attr.isEmpty())  return (this->getValue() == attr.getValue());
125    else return false;
126  }
127
128  template <class T>
129  int CAttributeEnum<T>::computeHash(void)
130  {
131    // Basic hash computation through string
132    return std::hash<string>{}( toString() );
133  }
134
135  //---------------------------------------------------------------
136
137  template <class T>
138  CAttributeEnum<T>& CAttributeEnum<T>::operator=(const T_enum & value)
139  {
140     this->setValue(value);
141     return *this;
142  }
143
144  //---------------------------------------------------------------
145
146  template <class T>
147  StdString CAttributeEnum<T>::_toString(void) const
148  {
149     StdOStringStream oss;
150     if (!CEnum<T>::isEmpty() && this->hasId())
151        oss << this->getName() << "=\"" << CEnum<T>::toString() << "\"";
152     return (oss.str());
153  }
154
155  template <class T>
156  void CAttributeEnum<T>::_fromString(const StdString & str)
157  {
158    CEnum<T>::fromString(str);
159  }
160
161  template <class T>
162  bool CAttributeEnum<T>::_toBuffer (CBufferOut& buffer) const
163  {
164     return CEnum<T>::toBuffer(buffer);
165  }
166
167  template <class T>
168  bool CAttributeEnum<T>::_fromBuffer(CBufferIn& buffer)
169  {
170    return CEnum<T>::fromBuffer(buffer);
171  }
172
173  template <typename T>
174  void CAttributeEnum<T>::generateCInterface(ostream& oss,const string& className)
175  {
176    CInterface::AttributeCInterface<CEnumBase>(oss, className, this->getName());
177  }
178
179  template <typename T>
180  void CAttributeEnum<T>::generateFortran2003Interface(ostream& oss,const string& className)
181  {
182    CInterface::AttributeFortran2003Interface<string>(oss, className, this->getName());
183  }
184
185  template <typename T>
186  void CAttributeEnum<T>::generateFortranInterfaceDeclaration_(ostream& oss,const string& className)
187  {
188    CInterface::AttributeFortranInterfaceDeclaration<string>(oss, className, this->getName()+"_");
189  }
190
191  template <typename T>
192  void CAttributeEnum<T>::generateFortranInterfaceBody_(ostream& oss,const string& className)
193  {
194    CInterface::AttributeFortranInterfaceBody<string>(oss, className, this->getName());
195  }
196
197  template <typename T>
198  void CAttributeEnum<T>::generateFortranInterfaceDeclaration(ostream& oss,const string& className)
199  {
200    CInterface::AttributeFortranInterfaceDeclaration<string>(oss, className, this->getName());
201  }
202
203  template <typename T>
204  void CAttributeEnum<T>::generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className)
205  {
206    CInterface::AttributeFortranInterfaceGetDeclaration<string>(oss, className, this->getName()+"_");
207  }
208
209  template <typename T>
210  void CAttributeEnum<T>::generateFortranInterfaceGetBody_(ostream& oss,const string& className)
211  {
212    CInterface::AttributeFortranInterfaceGetBody<string>(oss, className, this->getName());
213  }
214
215  template <typename T>
216  void CAttributeEnum<T>::generateFortranInterfaceGetDeclaration(ostream& oss,const string& className)
217  {
218    CInterface::AttributeFortranInterfaceGetDeclaration<string>(oss, className, this->getName());
219  }
220 
221  template <class T>
222  StdString CAttributeEnum<T>::_dumpGraph(void) const
223  {
224     StdOStringStream oss;
225     if (!CEnum<T>::isEmpty() && this->hasId())
226        oss << this->getName() << "=" << CEnum<T>::toString() << "</br>";
227     return (oss.str());
228  }
229} // namespace xios
230
231#endif // __XIOS_ATTRIBUTE_ENUM_IMPL_HPP__
Note: See TracBrowser for help on using the repository browser.