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

Last change on this file since 459 was 459, checked in by ymipsl, 10 years ago

Add new parsing expression functionnalities
(modified files)

YM

File size: 3.4 KB
RevLine 
[268]1#ifndef __XMLIO_CVariable__
2#define __XMLIO_CVariable__
3
[335]4/// xios headers ///
[268]5#include "xmlioserver_spl.hpp"
6#include "declare_group.hpp"
[459]7#include "group_template.hpp"
8#include "array_new.hpp"
[268]9
[335]10namespace xios
[268]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
[274]35            friend class CVariableGroup;
36
[268]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
[274]51         public :
52         
53            /// Autres ///
54            virtual void parse(xml::CXMLNode & node);
55            virtual StdString toString(void) const;
56
[369]57//            virtual void toBinary  (StdOStream & os) const;
58//            virtual void fromBinary(StdIStream & is);
[274]59
60            /// Accesseur ///
61            const StdString & getContent (void) const;
62
63           
[286]64            template <typename T> inline T getData(void) const;
65//            bool inline getData<bool>(void) const ;
[352]66//            template <> getData<bool>(void) const ;
[286]67           
[274]68            template <typename T, StdSize N>
[369]69            inline void getData(CArray<T, N>& _data_array) const;
[274]70
71         public :
72         
[268]73            /// Accesseurs statiques ///
74            static StdString GetName(void);
75            static StdString GetDefName(void);
76            static ENodeType GetType(void);
77
[274]78         private :
79
80            StdString content;
81
[268]82      }; // class CVar
83
[352]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     
[286]94      template <typename T>
[352]95      inline T CVariable::getData(void) const
[286]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
[352]106
[268]107      ///--------------------------------------------------------------
108
109      // Declare/Define CVarGroup and CVarDefinition
[274]110      DECLARE_GROUP_PARSE_REDEF(CVariable);
[268]111
112
113
[335]114} // namespace xios
[268]115
116#endif // __XMLIO_CVariable__
Note: See TracBrowser for help on using the repository browser.