source: XIOS3/branches/xios-3.0-beta/src/node/variable.hpp @ 2495

Last change on this file since 2495 was 2495, checked in by jderouillat, 14 months ago

Check that the parameters of the XIOS context are valid

  • 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.4 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#include "declare_attribute.hpp"
12
13namespace xios
14{
15      /// ////////////////////// Déclarations ////////////////////// ///
16
17      class CVariableGroup;
18      class CVariableAttributes;
19      class CVariable;
20      class CContext;
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      {
34                     /// typedef ///
35            typedef CObjectTemplate<CVariable>   SuperClass;
36            typedef CVariableAttributes SuperClassAttribute;
37           
38         public :
39            enum EEventId
40            {
41             EVENT_ID_COLLECTIVE=100,
42             EVENT_ID_VARIABLE_VALUE,
43             EVENT_ID_NO_COLLECTIVE=1000,
44            };
45
46            friend class CVariableGroup;
47
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
62         public :
63            /// Autres ///
64            virtual void parse(xml::CXMLNode & node);
65            virtual StdString toString(void) const;
66
67            /// Accesseur ///
68            const StdString& getVariableOutputName(void) const;
69            const StdString & getContent (void) const;
70
71            void setContent(const StdString& content);
72
73
74            template <typename T> inline T getData(void) const;
75            template <typename T> inline void setData(T data);
76
77            template <typename T, StdSize N>
78            inline void getData(CArray<T, N>& _data_array) const;
79
80            static bool dispatchEvent(CEventServer& event) ;
81
82            //! Sending a request to set up variable data
83            void sendValue(CContextClient* client);
84
85            static void recvValue(CEventServer& event) ;
86            void recvValue(CBufferIn& buffer) ;
87
88         public :
89
90            /// Accesseurs statiques ///
91            static StdString GetName(void);
92            static StdString GetDefName(void);
93            static ENodeType GetType(void);
94
95         private :
96
97            static void checkInDictionary(StdString id);
98            StdString content;
99
100      }; // class CVar
101
102      template <typename T>
103      inline T CVariable::getData(void) const
104      {
105         T retval ;
106         std::stringstream sstr(std::stringstream::in | std::stringstream::out);
107         sstr<<content ;
108         sstr>>retval ;
109         if (sstr.fail()) ERROR("CVariable::getdata()",
110               << "Cannot convert string <" << content << "> into type required" );
111         return retval ;
112      }
113
114      template<>
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<>
129      inline void CVariable::setData(bool data)
130      {
131        if (true == data) content.assign("true");
132        else content.assign("false");
133      }
134
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
143      ///--------------------------------------------------------------
144
145      // Declare/Define CVarGroup and CVarDefinition
146      DECLARE_GROUP_PARSE_REDEF(CVariable);
147} // namespace xios
148
149#endif // __XIOS_CVariable__
Note: See TracBrowser for help on using the repository browser.