[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" |
---|
[1158] | 11 | #include "declare_attribute.hpp" |
---|
[268] | 12 | |
---|
[335] | 13 | namespace xios |
---|
[268] | 14 | { |
---|
| 15 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 16 | |
---|
| 17 | class CVariableGroup; |
---|
| 18 | class CVariableAttributes; |
---|
| 19 | class CVariable; |
---|
[489] | 20 | class CContext; |
---|
[268] | 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 | { |
---|
[987] | 34 | /// typedef /// |
---|
| 35 | typedef CObjectTemplate<CVariable> SuperClass; |
---|
| 36 | typedef CVariableAttributes SuperClassAttribute; |
---|
| 37 | |
---|
| 38 | public : |
---|
[489] | 39 | enum EEventId |
---|
| 40 | { |
---|
| 41 | EVENT_ID_VARIABLE_VALUE |
---|
| 42 | }; |
---|
| 43 | |
---|
[274] | 44 | friend class CVariableGroup; |
---|
| 45 | |
---|
[268] | 46 | public : |
---|
| 47 | |
---|
| 48 | typedef CVariableAttributes RelAttributes; |
---|
| 49 | typedef CVariableGroup RelGroup; |
---|
| 50 | |
---|
| 51 | /// Constructeurs /// |
---|
| 52 | CVariable(void); |
---|
| 53 | explicit CVariable(const StdString & id); |
---|
| 54 | CVariable(const CVariable & var); // Not implemented yet. |
---|
| 55 | CVariable(const CVariable * const var); // Not implemented yet. |
---|
| 56 | |
---|
| 57 | /// Destructeur /// |
---|
| 58 | virtual ~CVariable(void); |
---|
| 59 | |
---|
[274] | 60 | public : |
---|
| 61 | /// Autres /// |
---|
| 62 | virtual void parse(xml::CXMLNode & node); |
---|
| 63 | virtual StdString toString(void) const; |
---|
| 64 | |
---|
| 65 | /// Accesseur /// |
---|
[773] | 66 | const StdString& getVariableOutputName(void) const; |
---|
[274] | 67 | const StdString & getContent (void) const; |
---|
[489] | 68 | |
---|
| 69 | void setContent(const StdString& content); |
---|
| 70 | |
---|
| 71 | |
---|
[286] | 72 | template <typename T> inline T getData(void) const; |
---|
[489] | 73 | template <typename T> inline void setData(T data); |
---|
| 74 | |
---|
[274] | 75 | template <typename T, StdSize N> |
---|
[369] | 76 | inline void getData(CArray<T, N>& _data_array) const; |
---|
[489] | 77 | |
---|
| 78 | static bool dispatchEvent(CEventServer& event) ; |
---|
| 79 | |
---|
| 80 | //! Sending a request to set up variable data |
---|
| 81 | void sendValue(); |
---|
[1071] | 82 | void sendValue(CContextClient* client, bool clientPrim = false); |
---|
[489] | 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 | |
---|
[286] | 100 | template <typename T> |
---|
[352] | 101 | inline T CVariable::getData(void) const |
---|
[286] | 102 | { |
---|
| 103 | T retval ; |
---|
[489] | 104 | std::stringstream sstr(std::stringstream::in | std::stringstream::out); |
---|
[286] | 105 | sstr<<content ; |
---|
| 106 | sstr>>retval ; |
---|
| 107 | if (sstr.fail()) ERROR("CVariable::getdata()", |
---|
| 108 | << "Cannot convert string <" << content << "> into type required" ); |
---|
| 109 | return retval ; |
---|
[489] | 110 | } |
---|
[286] | 111 | |
---|
[489] | 112 | template<> |
---|
[530] | 113 | inline bool CVariable::getData(void) const |
---|
| 114 | { |
---|
| 115 | if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; |
---|
| 116 | else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; |
---|
| 117 | else ERROR("CVariable::getdata()", |
---|
| 118 | << "Cannot convert string <" << content << "> into type required" ); |
---|
| 119 | return false ; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | template<> |
---|
| 123 | inline std::string CVariable::getData(void) const |
---|
| 124 | { return content; } |
---|
| 125 | |
---|
| 126 | template<> |
---|
[489] | 127 | inline void CVariable::setData(bool data) |
---|
| 128 | { |
---|
| 129 | if (true == data) content.assign("true"); |
---|
| 130 | else content.assign("false"); |
---|
| 131 | } |
---|
[352] | 132 | |
---|
[489] | 133 | template <typename T> |
---|
| 134 | inline void CVariable::setData(T data) |
---|
| 135 | { |
---|
| 136 | std::stringstream sstr; |
---|
| 137 | sstr<<data; |
---|
| 138 | content = sstr.str(); |
---|
| 139 | } |
---|
| 140 | |
---|
[268] | 141 | ///-------------------------------------------------------------- |
---|
| 142 | |
---|
| 143 | // Declare/Define CVarGroup and CVarDefinition |
---|
[274] | 144 | DECLARE_GROUP_PARSE_REDEF(CVariable); |
---|
[335] | 145 | } // namespace xios |
---|
[268] | 146 | |
---|
[591] | 147 | #endif // __XIOS_CVariable__ |
---|