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

Last change on this file since 1338 was 1041, checked in by rlacroix, 7 years ago

Add a new attribute "ts_target" for variables.

It allows choosing the target of the variable when using timeseries. Possible values are:

  • field
  • file
  • both
  • none.

If no value is set then the default behavior is used, that is "field" for field variables and "file" for file variables.

  • 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.2 KB
RevLine 
[591]1#ifndef __XIOS_CVariable__
2#define __XIOS_CVariable__
[268]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[268]6#include "declare_group.hpp"
[459]7#include "group_template.hpp"
8#include "array_new.hpp"
[527]9#include "attribute_enum.hpp"
10#include "attribute_enum_impl.hpp"
[1041]11#include "declare_attribute.hpp"
[268]12
[335]13namespace xios
[268]14{
15      /// ////////////////////// Déclarations ////////////////////// ///
16
17      class CVariableGroup;
18      class CVariableAttributes;
19      class CVariable;
[489]20      class CContext;
[268]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      {
[489]34            enum EEventId
35            {
36             EVENT_ID_VARIABLE_VALUE
37            };
38
[268]39            /// typedef ///
40            typedef CObjectTemplate<CVariable>   SuperClass;
41            typedef CVariableAttributes SuperClassAttribute;
42
[274]43            friend class CVariableGroup;
44
[268]45         public :
46
47            typedef CVariableAttributes RelAttributes;
48            typedef CVariableGroup      RelGroup;
49
50            /// Constructeurs ///
51            CVariable(void);
52            explicit CVariable(const StdString & id);
53            CVariable(const CVariable & var);       // Not implemented yet.
54            CVariable(const CVariable * const var); // Not implemented yet.
55
56            /// Destructeur ///
57            virtual ~CVariable(void);
58
[274]59         public :
60            /// Autres ///
61            virtual void parse(xml::CXMLNode & node);
62            virtual StdString toString(void) const;
63
64            /// Accesseur ///
[773]65            const StdString& getVariableOutputName(void) const;
[274]66            const StdString & getContent (void) const;
[489]67
68            void setContent(const StdString& content);
69
70
[286]71            template <typename T> inline T getData(void) const;
[489]72            template <typename T> inline void setData(T data);
73
[274]74            template <typename T, StdSize N>
[369]75            inline void getData(CArray<T, N>& _data_array) const;
[489]76
77            static bool dispatchEvent(CEventServer& event) ;
78
79            //! Sending a request to set up variable data
80            void sendValue();
81
82            static void recvValue(CEventServer& event) ;
83            void recvValue(CBufferIn& buffer) ;
84
[274]85         public :
[489]86
[268]87            /// Accesseurs statiques ///
88            static StdString GetName(void);
89            static StdString GetDefName(void);
90            static ENodeType GetType(void);
91
[274]92         private :
93
94            StdString content;
95
[268]96      }; // class CVar
97
[286]98      template <typename T>
[352]99      inline T CVariable::getData(void) const
[286]100      {
101         T retval ;
[489]102         std::stringstream sstr(std::stringstream::in | std::stringstream::out);
[286]103         sstr<<content ;
104         sstr>>retval ;
105         if (sstr.fail()) ERROR("CVariable::getdata()",
106               << "Cannot convert string <" << content << "> into type required" );
107         return retval ;
[489]108      }
[286]109
[489]110      template<>
[530]111      inline bool CVariable::getData(void) const
112      {
113         if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ;
114         else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ;
115         else ERROR("CVariable::getdata()",
116               << "Cannot convert string <" << content << "> into type required" );
117         return false ;
118      }
119
120      template<>
121      inline std::string CVariable::getData(void) const
122      { return content; }
123
124      template<>
[489]125      inline void CVariable::setData(bool data)
126      {
127        if (true == data) content.assign("true");
128        else content.assign("false");
129      }
[352]130
[489]131      template <typename T>
132      inline void CVariable::setData(T data)
133      {
134        std::stringstream sstr;
135        sstr<<data;
136        content = sstr.str();
137      }
138
[268]139      ///--------------------------------------------------------------
140
141      // Declare/Define CVarGroup and CVarDefinition
[274]142      DECLARE_GROUP_PARSE_REDEF(CVariable);
[335]143} // namespace xios
[268]144
[591]145#endif // __XIOS_CVariable__
Note: See TracBrowser for help on using the repository browser.