1 | #ifndef __XIOS_CVariable__ |
---|
2 | #define __XIOS_CVariable__ |
---|
3 | |
---|
4 | /// XIOS headers /// |
---|
5 | #include "xios_spl.hpp" |
---|
6 | #include "declare_group.hpp" |
---|
7 | #include "group_template.hpp" |
---|
8 | #include "array_new.hpp" |
---|
9 | #include "attribute_enum.hpp" |
---|
10 | #include "attribute_enum_impl.hpp" |
---|
11 | #include "declare_attribute.hpp" |
---|
12 | |
---|
13 | namespace xios |
---|
14 | { |
---|
15 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
16 | |
---|
17 | class CVariableGroup; |
---|
18 | class CVariableAttributes; |
---|
19 | class CVariable; |
---|
20 | class CContext; |
---|
21 | ///-------------------------------------------------------------- |
---|
22 | |
---|
23 | // Declare/Define CVarAttribute |
---|
24 | BEGIN_DECLARE_ATTRIBUTE_MAP(CVariable) |
---|
25 | #include "var_attribute.conf" |
---|
26 | END_DECLARE_ATTRIBUTE_MAP(CVariable) |
---|
27 | |
---|
28 | ///-------------------------------------------------------------- |
---|
29 | |
---|
30 | class CVariable |
---|
31 | : public CObjectTemplate<CVariable> |
---|
32 | , public CVariableAttributes |
---|
33 | { |
---|
34 | /// typedef /// |
---|
35 | typedef CObjectTemplate<CVariable> SuperClass; |
---|
36 | typedef CVariableAttributes SuperClassAttribute; |
---|
37 | |
---|
38 | public : |
---|
39 | enum EEventId |
---|
40 | { |
---|
41 | EVENT_ID_COLLECTIVE=100, |
---|
42 | EVENT_ID_VARIABLE_VALUE, |
---|
43 | EVENT_ID_NO_COLLECTIVE=1000, |
---|
44 | }; |
---|
45 | |
---|
46 | friend class CVariableGroup; |
---|
47 | |
---|
48 | public : |
---|
49 | |
---|
50 | typedef CVariableAttributes RelAttributes; |
---|
51 | typedef CVariableGroup RelGroup; |
---|
52 | |
---|
53 | /// Constructeurs /// |
---|
54 | CVariable(void); |
---|
55 | explicit CVariable(const StdString & id); |
---|
56 | CVariable(const CVariable & var); // Not implemented yet. |
---|
57 | CVariable(const CVariable * const var); // Not implemented yet. |
---|
58 | |
---|
59 | /// Destructeur /// |
---|
60 | virtual ~CVariable(void); |
---|
61 | |
---|
62 | public : |
---|
63 | /// Autres /// |
---|
64 | virtual void parse(xml::CXMLNode & node); |
---|
65 | virtual StdString toString(void) const; |
---|
66 | |
---|
67 | /// Accesseur /// |
---|
68 | const StdString& getVariableOutputName(void) const; |
---|
69 | const StdString & getContent (void) const; |
---|
70 | |
---|
71 | void setContent(const StdString& content); |
---|
72 | |
---|
73 | |
---|
74 | template <typename T> inline T getData(void) const; |
---|
75 | template <typename T> inline void setData(T data); |
---|
76 | |
---|
77 | template <typename T, StdSize N> |
---|
78 | inline void getData(CArray<T, N>& _data_array) const; |
---|
79 | |
---|
80 | static bool dispatchEvent(CEventServer& event) ; |
---|
81 | |
---|
82 | //! Sending a request to set up variable data |
---|
83 | void sendValue(CContextClient* client); |
---|
84 | |
---|
85 | static void recvValue(CEventServer& event) ; |
---|
86 | void recvValue(CBufferIn& buffer) ; |
---|
87 | |
---|
88 | public : |
---|
89 | |
---|
90 | /// Accesseurs statiques /// |
---|
91 | static StdString GetName(void); |
---|
92 | static StdString GetDefName(void); |
---|
93 | static ENodeType GetType(void); |
---|
94 | |
---|
95 | private : |
---|
96 | |
---|
97 | StdString content; |
---|
98 | |
---|
99 | }; // class CVar |
---|
100 | |
---|
101 | template <typename T> |
---|
102 | inline T CVariable::getData(void) const |
---|
103 | { |
---|
104 | T retval ; |
---|
105 | std::stringstream sstr(std::stringstream::in | std::stringstream::out); |
---|
106 | sstr<<content ; |
---|
107 | sstr>>retval ; |
---|
108 | if (sstr.fail()) ERROR("CVariable::getdata()", |
---|
109 | << "Cannot convert string <" << content << "> into type required" ); |
---|
110 | return retval ; |
---|
111 | } |
---|
112 | |
---|
113 | template<> |
---|
114 | inline bool CVariable::getData(void) const |
---|
115 | { |
---|
116 | if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; |
---|
117 | else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; |
---|
118 | else ERROR("CVariable::getdata()", |
---|
119 | << "Cannot convert string <" << content << "> into type required" ); |
---|
120 | return false ; |
---|
121 | } |
---|
122 | |
---|
123 | template<> |
---|
124 | inline std::string CVariable::getData(void) const |
---|
125 | { return content; } |
---|
126 | |
---|
127 | template<> |
---|
128 | inline void CVariable::setData(bool data) |
---|
129 | { |
---|
130 | if (true == data) content.assign("true"); |
---|
131 | else content.assign("false"); |
---|
132 | } |
---|
133 | |
---|
134 | template <typename T> |
---|
135 | inline void CVariable::setData(T data) |
---|
136 | { |
---|
137 | std::stringstream sstr; |
---|
138 | sstr<<data; |
---|
139 | content = sstr.str(); |
---|
140 | } |
---|
141 | |
---|
142 | ///-------------------------------------------------------------- |
---|
143 | |
---|
144 | // Declare/Define CVarGroup and CVarDefinition |
---|
145 | DECLARE_GROUP_PARSE_REDEF(CVariable); |
---|
146 | } // namespace xios |
---|
147 | |
---|
148 | #endif // __XIOS_CVariable__ |
---|