[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 | { |
---|
[2326] | 41 | EVENT_ID_COLLECTIVE=100, |
---|
| 42 | EVENT_ID_VARIABLE_VALUE, |
---|
| 43 | EVENT_ID_NO_COLLECTIVE=1000, |
---|
[489] | 44 | }; |
---|
| 45 | |
---|
[274] | 46 | friend class CVariableGroup; |
---|
| 47 | |
---|
[268] | 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 | |
---|
[274] | 62 | public : |
---|
| 63 | /// Autres /// |
---|
| 64 | virtual void parse(xml::CXMLNode & node); |
---|
| 65 | virtual StdString toString(void) const; |
---|
| 66 | |
---|
| 67 | /// Accesseur /// |
---|
[773] | 68 | const StdString& getVariableOutputName(void) const; |
---|
[274] | 69 | const StdString & getContent (void) const; |
---|
[489] | 70 | |
---|
| 71 | void setContent(const StdString& content); |
---|
| 72 | |
---|
| 73 | |
---|
[286] | 74 | template <typename T> inline T getData(void) const; |
---|
[489] | 75 | template <typename T> inline void setData(T data); |
---|
| 76 | |
---|
[274] | 77 | template <typename T, StdSize N> |
---|
[369] | 78 | inline void getData(CArray<T, N>& _data_array) const; |
---|
[489] | 79 | |
---|
| 80 | static bool dispatchEvent(CEventServer& event) ; |
---|
| 81 | |
---|
| 82 | //! Sending a request to set up variable data |
---|
[1784] | 83 | void sendValue(CContextClient* client); |
---|
[489] | 84 | |
---|
| 85 | static void recvValue(CEventServer& event) ; |
---|
| 86 | void recvValue(CBufferIn& buffer) ; |
---|
| 87 | |
---|
[274] | 88 | public : |
---|
[489] | 89 | |
---|
[268] | 90 | /// Accesseurs statiques /// |
---|
| 91 | static StdString GetName(void); |
---|
| 92 | static StdString GetDefName(void); |
---|
| 93 | static ENodeType GetType(void); |
---|
| 94 | |
---|
[274] | 95 | private : |
---|
| 96 | |
---|
[2495] | 97 | static void checkInDictionary(StdString id); |
---|
[274] | 98 | StdString content; |
---|
| 99 | |
---|
[268] | 100 | }; // class CVar |
---|
| 101 | |
---|
[286] | 102 | template <typename T> |
---|
[352] | 103 | inline T CVariable::getData(void) const |
---|
[286] | 104 | { |
---|
| 105 | T retval ; |
---|
[489] | 106 | std::stringstream sstr(std::stringstream::in | std::stringstream::out); |
---|
[286] | 107 | sstr<<content ; |
---|
| 108 | sstr>>retval ; |
---|
| 109 | if (sstr.fail()) ERROR("CVariable::getdata()", |
---|
| 110 | << "Cannot convert string <" << content << "> into type required" ); |
---|
| 111 | return retval ; |
---|
[489] | 112 | } |
---|
[286] | 113 | |
---|
[489] | 114 | template<> |
---|
[530] | 115 | inline bool CVariable::getData(void) const |
---|
| 116 | { |
---|
| 117 | if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; |
---|
| 118 | else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; |
---|
| 119 | else ERROR("CVariable::getdata()", |
---|
| 120 | << "Cannot convert string <" << content << "> into type required" ); |
---|
| 121 | return false ; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | template<> |
---|
| 125 | inline std::string CVariable::getData(void) const |
---|
| 126 | { return content; } |
---|
| 127 | |
---|
| 128 | template<> |
---|
[489] | 129 | inline void CVariable::setData(bool data) |
---|
| 130 | { |
---|
| 131 | if (true == data) content.assign("true"); |
---|
| 132 | else content.assign("false"); |
---|
| 133 | } |
---|
[352] | 134 | |
---|
[489] | 135 | template <typename T> |
---|
| 136 | inline void CVariable::setData(T data) |
---|
| 137 | { |
---|
| 138 | std::stringstream sstr; |
---|
| 139 | sstr<<data; |
---|
| 140 | content = sstr.str(); |
---|
| 141 | } |
---|
| 142 | |
---|
[268] | 143 | ///-------------------------------------------------------------- |
---|
| 144 | |
---|
| 145 | // Declare/Define CVarGroup and CVarDefinition |
---|
[274] | 146 | DECLARE_GROUP_PARSE_REDEF(CVariable); |
---|
[335] | 147 | } // namespace xios |
---|
[268] | 148 | |
---|
[591] | 149 | #endif // __XIOS_CVariable__ |
---|