source: XIOS3/trunk/src/attribute_array_impl.hpp @ 2433

Last change on this file since 2433 was 2388, checked in by jderouillat, 22 months ago

Manage hash values with size_t in hash tables of elements associated to output files

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