source: XIOS/trunk/src/node/variable.hpp @ 591

Last change on this file since 591 was 591, checked in by rlacroix, 9 years ago

Remove leftovers from the XMLIO age.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 4.1 KB
Line 
1#ifndef __XIOS_CVariable__
2#define __XIOS_CVariable__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "declare_group.hpp"
7#include "group_template.hpp"
8#include "array_new.hpp"
9#include "attribute_enum.hpp"
10#include "attribute_enum_impl.hpp"
11
12namespace xios
13{
14      /// ////////////////////// Déclarations ////////////////////// ///
15
16      class CVariableGroup;
17      class CVariableAttributes;
18      class CVariable;
19      class CContext;
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      {
33            enum EEventId
34            {
35             EVENT_ID_VARIABLE_VALUE
36            };
37
38            /// typedef ///
39            typedef CObjectTemplate<CVariable>   SuperClass;
40            typedef CVariableAttributes SuperClassAttribute;
41
42            friend class CVariableGroup;
43
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
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;
65
66            void setContent(const StdString& content);
67
68
69            template <typename T> inline T getData(void) const;
70            template <typename T> inline void setData(T data);
71
72            template <typename T, StdSize N>
73            inline void getData(CArray<T, N>& _data_array) const;
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
83         public :
84
85            /// Accesseurs statiques ///
86            static StdString GetName(void);
87            static StdString GetDefName(void);
88            static ENodeType GetType(void);
89
90         private :
91
92            StdString content;
93
94      }; // class CVar
95
96      template <typename T>
97      inline T CVariable::getData(void) const
98      {
99         T retval ;
100         std::stringstream sstr(std::stringstream::in | std::stringstream::out);
101         sstr<<content ;
102         sstr>>retval ;
103         if (sstr.fail()) ERROR("CVariable::getdata()",
104               << "Cannot convert string <" << content << "> into type required" );
105         return retval ;
106      }
107
108      template<>
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<>
123      inline void CVariable::setData(bool data)
124      {
125        if (true == data) content.assign("true");
126        else content.assign("false");
127      }
128
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
137      ///--------------------------------------------------------------
138
139      // Declare/Define CVarGroup and CVarDefinition
140      DECLARE_GROUP_PARSE_REDEF(CVariable);
141} // namespace xios
142
143#endif // __XIOS_CVariable__
Note: See TracBrowser for help on using the repository browser.