[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 | { |
---|
[987] | 33 | /// typedef /// |
---|
| 34 | typedef CObjectTemplate<CVariable> SuperClass; |
---|
| 35 | typedef CVariableAttributes SuperClassAttribute; |
---|
| 36 | |
---|
| 37 | public : |
---|
[489] | 38 | enum EEventId |
---|
| 39 | { |
---|
| 40 | EVENT_ID_VARIABLE_VALUE |
---|
| 41 | }; |
---|
| 42 | |
---|
[274] | 43 | friend class CVariableGroup; |
---|
| 44 | |
---|
[268] | 45 | public : |
---|
| 46 | |
---|
| 47 | typedef CVariableAttributes RelAttributes; |
---|
| 48 | typedef CVariableGroup RelGroup; |
---|
| 49 | |
---|
| 50 | /// Constructeurs /// |
---|
| 51 | CVariable(void); |
---|
| 52 | explicit CVariable(const StdString & id); |
---|
| 53 | CVariable(const CVariable & var); // Not implemented yet. |
---|
| 54 | CVariable(const CVariable * const var); // Not implemented yet. |
---|
| 55 | |
---|
| 56 | /// Destructeur /// |
---|
| 57 | virtual ~CVariable(void); |
---|
| 58 | |
---|
[274] | 59 | public : |
---|
| 60 | /// Autres /// |
---|
| 61 | virtual void parse(xml::CXMLNode & node); |
---|
| 62 | virtual StdString toString(void) const; |
---|
| 63 | |
---|
| 64 | /// Accesseur /// |
---|
[773] | 65 | const StdString& getVariableOutputName(void) const; |
---|
[274] | 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 | |
---|
| 77 | static bool dispatchEvent(CEventServer& event) ; |
---|
| 78 | |
---|
| 79 | //! Sending a request to set up variable data |
---|
| 80 | void sendValue(); |
---|
[1021] | 81 | void sendValue(CContextClient* client); |
---|
[489] | 82 | |
---|
| 83 | static void recvValue(CEventServer& event) ; |
---|
| 84 | void recvValue(CBufferIn& buffer) ; |
---|
| 85 | |
---|
[274] | 86 | public : |
---|
[489] | 87 | |
---|
[268] | 88 | /// Accesseurs statiques /// |
---|
| 89 | static StdString GetName(void); |
---|
| 90 | static StdString GetDefName(void); |
---|
| 91 | static ENodeType GetType(void); |
---|
| 92 | |
---|
[274] | 93 | private : |
---|
| 94 | |
---|
| 95 | StdString content; |
---|
| 96 | |
---|
[268] | 97 | }; // class CVar |
---|
| 98 | |
---|
[286] | 99 | template <typename T> |
---|
[352] | 100 | inline T CVariable::getData(void) const |
---|
[286] | 101 | { |
---|
| 102 | T retval ; |
---|
[489] | 103 | std::stringstream sstr(std::stringstream::in | std::stringstream::out); |
---|
[286] | 104 | sstr<<content ; |
---|
| 105 | sstr>>retval ; |
---|
| 106 | if (sstr.fail()) ERROR("CVariable::getdata()", |
---|
| 107 | << "Cannot convert string <" << content << "> into type required" ); |
---|
| 108 | return retval ; |
---|
[489] | 109 | } |
---|
[286] | 110 | |
---|
[489] | 111 | template<> |
---|
[530] | 112 | inline bool CVariable::getData(void) const |
---|
| 113 | { |
---|
| 114 | if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; |
---|
| 115 | else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; |
---|
| 116 | else ERROR("CVariable::getdata()", |
---|
| 117 | << "Cannot convert string <" << content << "> into type required" ); |
---|
| 118 | return false ; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | template<> |
---|
| 122 | inline std::string CVariable::getData(void) const |
---|
| 123 | { return content; } |
---|
| 124 | |
---|
| 125 | template<> |
---|
[489] | 126 | inline void CVariable::setData(bool data) |
---|
| 127 | { |
---|
| 128 | if (true == data) content.assign("true"); |
---|
| 129 | else content.assign("false"); |
---|
| 130 | } |
---|
[352] | 131 | |
---|
[489] | 132 | template <typename T> |
---|
| 133 | inline void CVariable::setData(T data) |
---|
| 134 | { |
---|
| 135 | std::stringstream sstr; |
---|
| 136 | sstr<<data; |
---|
| 137 | content = sstr.str(); |
---|
| 138 | } |
---|
| 139 | |
---|
[268] | 140 | ///-------------------------------------------------------------- |
---|
| 141 | |
---|
| 142 | // Declare/Define CVarGroup and CVarDefinition |
---|
[274] | 143 | DECLARE_GROUP_PARSE_REDEF(CVariable); |
---|
[335] | 144 | } // namespace xios |
---|
[268] | 145 | |
---|
[591] | 146 | #endif // __XIOS_CVariable__ |
---|