source: XIOS/dev/dev_trunk_graph/src/attribute_template.hpp @ 2030

Last change on this file since 2030 was 2019, checked in by yushan, 3 years ago

Graph intermedia commit to a tmp branch

  • 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: 5.6 KB
Line 
1#ifndef __XIOS_CAttributeTemplate__
2#define __XIOS_CAttributeTemplate__
3
4/// boost headers ///
5#include <boost/lexical_cast.hpp>
6
7/// XIOS headers ///
8#include "xios_spl.hpp"
9#include "exception.hpp"
10#include "attribute.hpp"
11#include "buffer_in.hpp"
12#include "buffer_out.hpp"
13#include "type.hpp"
14#include "tv_data_display.h"
15
16#ifdef __GNUC__
17#include <typeinfo>
18#include <cxxabi.h>
19#endif
20
21namespace xios
22{
23      /// ////////////////////// Déclarations ////////////////////// ///
24  /*!
25    \class CAttributeTemplate
26    The class implements attribute of some basic types
27  */
28       template <class T>
29         class CAttributeTemplate : public CAttribute, public CType<T>
30      {
31            typedef CAttribute SuperClass;
32
33         public :
34
35            /// Typedef ///
36            typedef T ValueType;
37
38            /// Constructeurs ///
39            explicit CAttributeTemplate(const StdString & id);
40            CAttributeTemplate(const StdString & id,
41                               xios_map<StdString, CAttribute*> & umap);
42            CAttributeTemplate(const StdString & id, const ValueType & value);
43            CAttributeTemplate(const StdString & id, const ValueType & value,
44                               xios_map<StdString, CAttribute*> & umap);
45
46          public :
47
48            /// Accesseur ///
49            ValueType getValue(void) const;
50
51            /// Mutateurs ///
52            void setValue(const ValueType & value);
53
54            void set(const CAttribute& attr) ;
55            void set(const CAttributeTemplate& attr) ;
56            void reset(void) ;
57            void checkEmpty(void) const;
58
59
60            void setInheritedValue(const CAttributeTemplate& attr );
61            void setInheritedValue(const CAttribute& attr );
62            T getInheritedValue(void) const ;
63            bool hasInheritedValue(void) const;
64           
65            bool isEqual(const CAttribute& attr );
66
67            /// Destructeur ///
68            virtual ~CAttributeTemplate(void) { }
69
70            /// Operateur ///
71            CAttributeTemplate& operator=(const ValueType & value);
72
73            /// Autre ///
74            virtual StdString toString(void) const { return _toString();}
75            virtual void fromString(const StdString & str) { if (str==resetInheritanceStr) { reset(); _canInherite=false ;}  else _fromString(str);}
76
77            virtual StdString dump(void) const { return _dump();}
78            virtual StdString dumpGraph(void) const { return _dumpGraph();}
79
80            virtual bool toBuffer  (CBufferOut& buffer) const { return _toBuffer(buffer);}
81            virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer); }
82            virtual void generateCInterface(ostream& oss,const string& className) ;
83            virtual void generateFortran2003Interface(ostream& oss,const string& className) ;
84            virtual void generateFortranInterfaceDeclaration_(ostream& oss,const string& className) ;
85            virtual void generateFortranInterfaceBody_(ostream& oss,const string& className) ;
86            virtual void generateFortranInterfaceDeclaration(ostream& oss,const string& className) ;
87            virtual void generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) ;
88            virtual void generateFortranInterfaceGetBody_(ostream& oss,const string& className) ;
89            virtual void generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) ;
90
91           static int show_TV_ttf_display_type ( const CAttributeTemplate<T>* attr)
92           {
93             int status ;
94             if (attr->isEmpty()) 
95             {
96               status = TV_ttf_add_row("State", TV_ttf_type_ascii_string,"(empty)") ;
97               if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
98               else return TV_ttf_format_ok_elide ;
99             }
100             else 
101             {
102               char tname[128] ;
103               char bname[128] = "ValueType" ;
104#ifdef __GNUC__
105               size_t size = sizeof(bname) ;
106               abi::__cxa_demangle(typeid(T).name(), bname, &size, &status) ;
107               if (status !=0) return TV_ttf_format_raw ;
108#endif
109               snprintf (tname, sizeof(tname), "%s", bname);
110               if (typeid(T)==typeid(string))
111                 status = TV_ttf_add_row("values", TV_ttf_type_ascii_string, ((string*)(attr->ptrValue))->c_str() );
112               else status = TV_ttf_add_row("values", tname, attr->ptrValue) ;
113               if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
114               else return TV_ttf_format_ok_elide ;
115             }
116           }
117     
118           static int TV_ttf_display_type ( const CAttributeTemplate<T>* attr )
119           {
120             return show_TV_ttf_display_type (attr) ;
121           }
122
123
124         protected :
125
126            /// Constructeurs ///
127//            CAttributeTemplate(void); // Not implemented.
128         private :
129          bool isEqual_(const CAttributeTemplate& attr);
130          StdString _toString(void) const;
131          StdString _dump(void) const;
132          StdString _dumpGraph(void) const;
133          void _fromString(const StdString & str);
134          bool _toBuffer  (CBufferOut& buffer) const;
135          bool _fromBuffer(CBufferIn& buffer) ;
136
137          CType<T> inheritedValue ;
138      }; // class CAttribute
139
140#define macrotype(_TYPE_)\
141  template<> int CAttributeTemplate<_TYPE_>::TV_ttf_display_type( const CAttributeTemplate<_TYPE_>* attr ) \
142  {\
143    return show_TV_ttf_display_type (attr) ;\
144  }
145
146macrotype(double)
147macrotype(int)
148macrotype(bool)
149macrotype(string)
150//macrotype(CDate)
151//macrotype(CDuration)
152#undef macrotype
153
154   template <class T>  void FromBinary(StdIStream & is, T & obj);
155
156
157} // namespace xios
158
159#endif // __XIOS_CAttributeTemplate__
Note: See TracBrowser for help on using the repository browser.