source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/variable.hpp @ 1853

Last change on this file since 1853 was 1784, checked in by ymipsl, 4 years ago
  • Preparing coupling functionalities.
  • Make some cleaner things

YM

  • 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.3 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_VARIABLE_VALUE
42            };
43
44            friend class CVariableGroup;
45
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
60         public :
61            /// Autres ///
62            virtual void parse(xml::CXMLNode & node);
63            virtual StdString toString(void) const;
64
65            /// Accesseur ///
66            const StdString& getVariableOutputName(void) const;
67            const StdString & getContent (void) const;
68
69            void setContent(const StdString& content);
70
71
72            template <typename T> inline T getData(void) const;
73            template <typename T> inline void setData(T data);
74
75            template <typename T, StdSize N>
76            inline void getData(CArray<T, N>& _data_array) const;
77
78            static bool dispatchEvent(CEventServer& event) ;
79
80            //! Sending a request to set up variable data
81            void sendValue(CContextClient* client);
82
83            static void recvValue(CEventServer& event) ;
84            void recvValue(CBufferIn& buffer) ;
85
86         public :
87
88            /// Accesseurs statiques ///
89            static StdString GetName(void);
90            static StdString GetDefName(void);
91            static ENodeType GetType(void);
92
93         private :
94
95            StdString content;
96
97      }; // class CVar
98
99      template <typename T>
100      inline T CVariable::getData(void) const
101      {
102         T retval ;
103         std::stringstream sstr(std::stringstream::in | std::stringstream::out);
104         sstr<<content ;
105         sstr>>retval ;
106         if (sstr.fail()) ERROR("CVariable::getdata()",
107               << "Cannot convert string <" << content << "> into type required" );
108         return retval ;
109      }
110
111      template<>
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<>
126      inline void CVariable::setData(bool data)
127      {
128        if (true == data) content.assign("true");
129        else content.assign("false");
130      }
131
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
140      ///--------------------------------------------------------------
141
142      // Declare/Define CVarGroup and CVarDefinition
143      DECLARE_GROUP_PARSE_REDEF(CVariable);
144} // namespace xios
145
146#endif // __XIOS_CVariable__
Note: See TracBrowser for help on using the repository browser.