source: XMLIO_V2/dev/common/src/node/variable.hpp @ 300

Last change on this file since 300 was 286, checked in by ymipsl, 13 years ago

reprise en main de la version de H. Ozdoba. Correction de différentes erreurs de conception et bug.
Version NEMO operationnel en client/server, interoperabilita avec OASIS, reconstition de fichiers via netcdf4/HDF5

YM

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