source: XIOS/dev/dev_ym/XIOS_COUPLING/src/attribute_array.hpp @ 1875

Last change on this file since 1875 was 1875, checked in by ymipsl, 4 years ago

XIOS coupling branch
Some updates.

First coupling test is beginning to work...

YM

  • 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.5 KB
Line 
1#ifndef __XIOS_ATTRIBUTE_ARRAY__
2#define __XIOS_ATTRIBUTE_ARRAY__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "exception.hpp"
7#include "attribute.hpp"
8#include "buffer_in.hpp"
9#include "buffer_out.hpp"
10#include "array_new.hpp"
11
12namespace xios
13{
14      /// ////////////////////// Déclarations ////////////////////// ///
15      /*!
16        \class CAttributeArray
17        This class implements the attribute representing array of value
18      */
19      template <typename T_numtype, int N_rank>
20         class CAttributeArray : public CAttribute, public CArray<T_numtype, N_rank>
21      {
22        public :
23            using CArray<T_numtype,N_rank>::operator = ;
24
25            /// Constructeurs ///
26            explicit CAttributeArray(const StdString & id);
27            CAttributeArray(const StdString & id, xios_map<StdString, CAttribute*> & umap);
28            CAttributeArray(const StdString & id, const CArray<T_numtype, N_rank>& value);
29            CAttributeArray(const StdString & id, const CArray<T_numtype, N_rank>& value,
30                           xios_map<StdString, CAttribute*> & umap);
31
32            /// Accesseur ///
33            CArray<T_numtype, N_rank> getValue(void) const;
34
35            /// Mutateurs ///
36            void setValue(const CArray<T_numtype, N_rank>& value);
37            void set(const CAttribute& attr) ;
38            void set(const CAttributeArray& attr) ;
39            void reset(void) ;
40            void setInheritedValue(const CAttributeArray& attr );
41            void setInheritedValue(const CAttribute& attr );
42            CArray<T_numtype, N_rank> getInheritedValue(void) const ;
43            bool hasInheritedValue(void) const;
44                       
45            bool isEqual(const CAttribute& attr);
46
47            /// Destructeur ///
48            virtual ~CAttributeArray(void) { }
49
50
51            /// Autre ///
52            virtual string toString(void) const { return _toString();}
53            virtual void fromString(const StdString & str) { if (str==resetInheritanceStr) { reset(); _canInherite=false ;}  else _fromString(str);}
54            virtual bool toBuffer  (CBufferOut& buffer) const { return _toBuffer(buffer);}
55            virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer); }
56            virtual string dump(void) const { return _dump();}
57
58            virtual void generateCInterface(ostream& oss,const string& className) ;
59            virtual void generateFortran2003Interface(ostream& oss,const string& className) ;
60            virtual void generateFortranInterfaceDeclaration_(ostream& oss,const string& className) ;
61            virtual void generateFortranInterfaceBody_(ostream& oss,const string& className) ;
62            virtual void generateFortranInterfaceDeclaration(ostream& oss,const string& className) ;
63            virtual void generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) ;
64            virtual void generateFortranInterfaceGetBody_(ostream& oss,const string& className) ;
65            virtual void generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) ;
66 
67 static int show_TV_ttf_display_type ( const CAttributeArray<T_numtype,N_rank>* array )
68      {
69        int status ;
70        if (array->isEmpty()) 
71        {
72          status = TV_ttf_add_row("State", TV_ttf_type_ascii_string,"(empty)") ;
73          if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
74          else return TV_ttf_format_ok_elide ;
75        }
76        else 
77        {
78          char tname[128] ;
79          char bname[128] = "value_type" ;
80#ifdef __GNUC__
81         size_t size = sizeof(bname) ;
82         abi::__cxa_demangle(typeid(T_numtype).name(), bname, &size, &status) ;
83         if (status !=0) return TV_ttf_format_raw ;
84#endif
85          int dim = array->dimensions() ;
86          if (dim==1) snprintf (tname, sizeof(tname), "%s[%d]", bname, array->extent(0));
87          if (dim==2) snprintf (tname, sizeof(tname), "%s[%d][%d]", bname, array->extent(1), array->extent(0));
88          if (dim==3) snprintf (tname, sizeof(tname), "%s[%d][%d][%d]", bname, array->extent(2), array->extent(1), array->extent(3));
89          if (dim==4) snprintf (tname, sizeof(tname), "%s[%d][%d][%d][%d]", bname, array->extent(0), array->extent(1), array->extent(2), array->extent(3));
90          if (dim==5) snprintf (tname, sizeof(tname), "%s[%d][%d][%d][%d][%d]", bname, array->extent(4), array->extent(3), array->extent(2), array->extent(1)
91                                                                                      ,array->extent(0));
92          if (dim==6) snprintf (tname, sizeof(tname), "%s[%d][%d][%d][%d][%d][%d]", bname, array->extent(5), array->extent(4), array->extent(3), array->extent(2)
93                                                                                      ,array->extent(1),array->extent(0));
94          if (dim==7) snprintf (tname, sizeof(tname), "%s[%d][%d][%d][%d][%d][%d][%d]", bname, array->extent(6), array->extent(5), array->extent(4), array->extent(3)
95                                                                                      ,array->extent(2),array->extent(1),array->extent(0));
96          status = TV_ttf_add_row("array_values", tname, array->dataFirst()) ;
97          if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
98          else return TV_ttf_format_ok ;
99        }
100      }
101     
102           
103            static int TV_ttf_display_type ( const  CAttributeArray<T_numtype,N_rank>* array )
104           {
105             return CAttributeArray<T_numtype,N_rank>::show_TV_ttf_display_type (array) ;
106           }
107
108         private :
109          bool isEqual_(const CAttributeArray& attr);
110          CArray<T_numtype, N_rank> inheritedValue ;
111          StdString _toString(void) const;
112          StdString _dump(void) const;
113          void _fromString(const StdString & str);
114          bool _toBuffer  (CBufferOut& buffer) const;
115          bool _fromBuffer(CBufferIn& buffer) ;
116      }; // class CAttributeEnum
117
118
119#define macrotyperank(_TYPE_,_RANK_)\
120  template<> int CAttributeArray<_TYPE_,_RANK_>::TV_ttf_display_type(const CAttributeArray<_TYPE_,_RANK_>* array ) \
121  {\
122    return CAttributeArray<_TYPE_,_RANK_>::show_TV_ttf_display_type (array) ;\
123  }
124
125#define macrotype(_TYPE_)\
126macrotyperank(_TYPE_,1)\
127macrotyperank(_TYPE_,2)\
128macrotyperank(_TYPE_,3)\
129macrotyperank(_TYPE_,4)\
130macrotyperank(_TYPE_,5)\
131macrotyperank(_TYPE_,6)\
132macrotyperank(_TYPE_,7)
133
134macrotype(double)
135macrotype(int)
136macrotype(bool)
137macrotype(size_t)
138macrotype(float)
139macrotype(string)
140
141#undef macrotyperank
142#undef macrotype
143} // namespace xios
144
145#endif // __XIOS_ATTRIBUTE_ARRAY__
Note: See TracBrowser for help on using the repository browser.