1 | #ifndef __XMLIO_CVariable__ |
---|
2 | #define __XMLIO_CVariable__ |
---|
3 | |
---|
4 | /// xios headers /// |
---|
5 | #include "xmlioserver_spl.hpp" |
---|
6 | #include "declare_group.hpp" |
---|
7 | #include "group_template.hpp" |
---|
8 | #include "array_new.hpp" |
---|
9 | |
---|
10 | namespace xios |
---|
11 | { |
---|
12 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
13 | |
---|
14 | class CVariableGroup; |
---|
15 | class CVariableAttributes; |
---|
16 | class CVariable; |
---|
17 | |
---|
18 | ///-------------------------------------------------------------- |
---|
19 | |
---|
20 | // Declare/Define CVarAttribute |
---|
21 | BEGIN_DECLARE_ATTRIBUTE_MAP(CVariable) |
---|
22 | #include "var_attribute.conf" |
---|
23 | END_DECLARE_ATTRIBUTE_MAP(CVariable) |
---|
24 | |
---|
25 | ///-------------------------------------------------------------- |
---|
26 | |
---|
27 | class CVariable |
---|
28 | : public CObjectTemplate<CVariable> |
---|
29 | , public CVariableAttributes |
---|
30 | { |
---|
31 | /// typedef /// |
---|
32 | typedef CObjectTemplate<CVariable> SuperClass; |
---|
33 | typedef CVariableAttributes SuperClassAttribute; |
---|
34 | |
---|
35 | friend class CVariableGroup; |
---|
36 | |
---|
37 | public : |
---|
38 | |
---|
39 | typedef CVariableAttributes RelAttributes; |
---|
40 | typedef CVariableGroup RelGroup; |
---|
41 | |
---|
42 | /// Constructeurs /// |
---|
43 | CVariable(void); |
---|
44 | explicit CVariable(const StdString & id); |
---|
45 | CVariable(const CVariable & var); // Not implemented yet. |
---|
46 | CVariable(const CVariable * const var); // Not implemented yet. |
---|
47 | |
---|
48 | /// Destructeur /// |
---|
49 | virtual ~CVariable(void); |
---|
50 | |
---|
51 | public : |
---|
52 | enum EVarType |
---|
53 | { t_int, t_short_int, t_long_int, t_float, t_double, t_long_double, t_bool, t_string, t_undefined } ; |
---|
54 | |
---|
55 | |
---|
56 | /// Autres /// |
---|
57 | virtual void parse(xml::CXMLNode & node); |
---|
58 | virtual StdString toString(void) const; |
---|
59 | |
---|
60 | /// Accesseur /// |
---|
61 | const StdString & getContent (void) const; |
---|
62 | |
---|
63 | |
---|
64 | template <typename T> inline T getData(void) const; |
---|
65 | |
---|
66 | template <typename T, StdSize N> |
---|
67 | inline void getData(CArray<T, N>& _data_array) const; |
---|
68 | |
---|
69 | EVarType getVarType(void) const ; |
---|
70 | |
---|
71 | public : |
---|
72 | |
---|
73 | /// Accesseurs statiques /// |
---|
74 | static StdString GetName(void); |
---|
75 | static StdString GetDefName(void); |
---|
76 | static ENodeType GetType(void); |
---|
77 | |
---|
78 | private : |
---|
79 | |
---|
80 | StdString content; |
---|
81 | |
---|
82 | }; // class CVar |
---|
83 | |
---|
84 | template<> |
---|
85 | inline bool CVariable::getData(void) const |
---|
86 | { |
---|
87 | if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; |
---|
88 | else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; |
---|
89 | else ERROR("CVariable::getdata()", |
---|
90 | << "Cannot convert string <" << content << "> into type required" ); |
---|
91 | return false ; |
---|
92 | } |
---|
93 | |
---|
94 | template <typename T> |
---|
95 | inline T CVariable::getData(void) const |
---|
96 | { |
---|
97 | T retval ; |
---|
98 | std::stringstream sstr(std::stringstream::in | std::stringstream::out); |
---|
99 | sstr<<content ; |
---|
100 | sstr>>retval ; |
---|
101 | if (sstr.fail()) ERROR("CVariable::getdata()", |
---|
102 | << "Cannot convert string <" << content << "> into type required" ); |
---|
103 | return retval ; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | ///-------------------------------------------------------------- |
---|
108 | |
---|
109 | // Declare/Define CVarGroup and CVarDefinition |
---|
110 | DECLARE_GROUP_PARSE_REDEF(CVariable); |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | } // namespace xios |
---|
115 | |
---|
116 | #endif // __XMLIO_CVariable__ |
---|