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 | |
---|
12 | namespace 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_)\ |
---|
126 | macrotyperank(_TYPE_,1)\ |
---|
127 | macrotyperank(_TYPE_,2)\ |
---|
128 | macrotyperank(_TYPE_,3)\ |
---|
129 | macrotyperank(_TYPE_,4)\ |
---|
130 | macrotyperank(_TYPE_,5)\ |
---|
131 | macrotyperank(_TYPE_,6)\ |
---|
132 | macrotyperank(_TYPE_,7) |
---|
133 | |
---|
134 | macrotype(double) |
---|
135 | macrotype(int) |
---|
136 | macrotype(bool) |
---|
137 | macrotype(size_t) |
---|
138 | macrotype(float) |
---|
139 | macrotype(string) |
---|
140 | |
---|
141 | #undef macrotyperank |
---|
142 | #undef macrotype |
---|
143 | } // namespace xios |
---|
144 | |
---|
145 | #endif // __XIOS_ATTRIBUTE_ARRAY__ |
---|