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