source: vendor/nemo/current/NEMOGCM/EXTERNAL/XIOS/src/node/variable.hpp @ 44

Last change on this file since 44 was 44, checked in by cholod, 12 years ago

Load NEMO_TMP into vendor/nemo/current.

File size: 3.4 KB
Line 
1#ifndef __XMLIO_CVariable__
2#define __XMLIO_CVariable__
3
4/// xios headers ///
5#include "xmlioserver_spl.hpp"
6#include "declare_group.hpp"
7
8#include "data_output.hpp"
9
10namespace xios
11{
12      /// ////////////////////// Déclarations ////////////////////// ///
13
14      class CVariableGroup;
15      class CVariableAttributes;
16      class CVariable;
17
18      ///--------------------------------------------------------------
19
20      // Declare/Define CVarAttribute
21      BEGIN_DECLARE_ATTRIBUTE_MAP(CVariable)
22#include "var_attribute.conf"
23      END_DECLARE_ATTRIBUTE_MAP(CVariable)
24
25      ///--------------------------------------------------------------
26
27      class CVariable
28         : public CObjectTemplate<CVariable>
29         , public CVariableAttributes
30      {
31            /// typedef ///
32            typedef CObjectTemplate<CVariable>   SuperClass;
33            typedef CVariableAttributes SuperClassAttribute;
34
35            friend class CVariableGroup;
36
37         public :
38
39            typedef CVariableAttributes RelAttributes;
40            typedef CVariableGroup      RelGroup;
41
42            /// Constructeurs ///
43            CVariable(void);
44            explicit CVariable(const StdString & id);
45            CVariable(const CVariable & var);       // Not implemented yet.
46            CVariable(const CVariable * const var); // Not implemented yet.
47
48            /// Destructeur ///
49            virtual ~CVariable(void);
50
51         public :
52         
53            /// Autres ///
54            virtual void parse(xml::CXMLNode & node);
55            virtual StdString toString(void) const;
56
57            virtual void toBinary  (StdOStream & os) const;
58            virtual void fromBinary(StdIStream & is);
59
60            /// Accesseur ///
61            const StdString & getContent (void) const;
62
63           
64            template <typename T> inline T getData(void) const;
65//            bool inline getData<bool>(void) const ;
66//            template <> getData<bool>(void) const ;
67           
68            template <typename T, StdSize N>
69               inline void getData(ARRAY(T, N) _data_array) const;
70
71         public :
72         
73            /// Accesseurs statiques ///
74            static StdString GetName(void);
75            static StdString GetDefName(void);
76            static ENodeType GetType(void);
77
78         private :
79
80            StdString content;
81
82      }; // class CVar
83
84      template<>
85      inline bool CVariable::getData(void) const
86      {
87         if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; 
88         else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; 
89         else ERROR("CVariable::getdata()",
90               << "Cannot convert string <" << content << "> into type required" );
91         return false ;
92      } 
93     
94      template <typename T>
95      inline T CVariable::getData(void) const
96      {
97         T retval ;
98         std::stringstream sstr(std::stringstream::in | std::stringstream::out); 
99         sstr<<content ;
100         sstr>>retval ;
101         if (sstr.fail()) ERROR("CVariable::getdata()",
102               << "Cannot convert string <" << content << "> into type required" );
103         return retval ;
104      } 
105
106
107      ///--------------------------------------------------------------
108
109      // Declare/Define CVarGroup and CVarDefinition
110      DECLARE_GROUP_PARSE_REDEF(CVariable);
111
112
113
114} // namespace xios
115
116#endif // __XMLIO_CVariable__
Note: See TracBrowser for help on using the repository browser.