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