source: XIOS/dev/dev_trunk_graph/src/attribute_array.hpp @ 2030

Last change on this file since 2030 was 2019, checked in by yushan, 3 years ago

Graph intermedia commit to a tmp branch

  • 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.6 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            virtual string dumpGraph(void) const { return _dumpGraph();}
58
59            virtual void generateCInterface(ostream& oss,const string& className) ;
60            virtual void generateFortran2003Interface(ostream& oss,const string& className) ;
61            virtual void generateFortranInterfaceDeclaration_(ostream& oss,const string& className) ;
62            virtual void generateFortranInterfaceBody_(ostream& oss,const string& className) ;
63            virtual void generateFortranInterfaceDeclaration(ostream& oss,const string& className) ;
64            virtual void generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) ;
65            virtual void generateFortranInterfaceGetBody_(ostream& oss,const string& className) ;
66            virtual void generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) ;
67 
68 static int show_TV_ttf_display_type ( const CAttributeArray<T_numtype,N_rank>* array )
69      {
70        int status ;
71        if (array->isEmpty()) 
72        {
73          status = TV_ttf_add_row("State", TV_ttf_type_ascii_string,"(empty)") ;
74          if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
75          else return TV_ttf_format_ok_elide ;
76        }
77        else 
78        {
79          char tname[128] ;
80          char bname[128] = "value_type" ;
81#ifdef __GNUC__
82         size_t size = sizeof(bname) ;
83         abi::__cxa_demangle(typeid(T_numtype).name(), bname, &size, &status) ;
84         if (status !=0) return TV_ttf_format_raw ;
85#endif
86          int dim = array->dimensions() ;
87          if (dim==1) snprintf (tname, sizeof(tname), "%s[%d]", bname, array->extent(0));
88          if (dim==2) snprintf (tname, sizeof(tname), "%s[%d][%d]", bname, array->extent(1), array->extent(0));
89          if (dim==3) snprintf (tname, sizeof(tname), "%s[%d][%d][%d]", bname, array->extent(2), array->extent(1), array->extent(3));
90          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));
91          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)
92                                                                                      ,array->extent(0));
93          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)
94                                                                                      ,array->extent(1),array->extent(0));
95          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)
96                                                                                      ,array->extent(2),array->extent(1),array->extent(0));
97          status = TV_ttf_add_row("array_values", tname, array->dataFirst()) ;
98          if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
99          else return TV_ttf_format_ok ;
100        }
101      }
102     
103           
104            static int TV_ttf_display_type ( const  CAttributeArray<T_numtype,N_rank>* array )
105           {
106             return CAttributeArray<T_numtype,N_rank>::show_TV_ttf_display_type (array) ;
107           }
108
109         private :
110          bool isEqual_(const CAttributeArray& attr);
111          CArray<T_numtype, N_rank> inheritedValue ;
112          StdString _toString(void) const;
113          StdString _dump(void) const;
114          StdString _dumpGraph(void) const;
115          void _fromString(const StdString & str);
116          bool _toBuffer  (CBufferOut& buffer) const;
117          bool _fromBuffer(CBufferIn& buffer) ;
118      }; // class CAttributeEnum
119
120
121#define macrotyperank(_TYPE_,_RANK_)\
122  template<> int CAttributeArray<_TYPE_,_RANK_>::TV_ttf_display_type(const CAttributeArray<_TYPE_,_RANK_>* array ) \
123  {\
124    return CAttributeArray<_TYPE_,_RANK_>::show_TV_ttf_display_type (array) ;\
125  }
126
127#define macrotype(_TYPE_)\
128macrotyperank(_TYPE_,1)\
129macrotyperank(_TYPE_,2)\
130macrotyperank(_TYPE_,3)\
131macrotyperank(_TYPE_,4)\
132macrotyperank(_TYPE_,5)\
133macrotyperank(_TYPE_,6)\
134macrotyperank(_TYPE_,7)
135
136macrotype(double)
137macrotype(int)
138macrotype(bool)
139macrotype(size_t)
140macrotype(float)
141macrotype(string)
142
143#undef macrotyperank
144#undef macrotype
145} // namespace xios
146
147#endif // __XIOS_ATTRIBUTE_ARRAY__
Note: See TracBrowser for help on using the repository browser.