source: XIOS/dev/dev_ym/XIOS_COUPLING/src/attribute_template.hpp @ 1878

Last change on this file since 1878 was 1875, checked in by ymipsl, 4 years ago

XIOS coupling branch
Some updates.

First coupling test is beginning to work...

YM

  • 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: 6.3 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//            CAttributeTemplate(const CAttribute & attribut) throw (CException);
46//            CAttributeTemplate(const CAttribute * const attribut); // Not implemented.
47
48          public :
49
50            /// Accesseur ///
51            ValueType getValue(void) const;
52//            ValueType* getRef(void) ;
53
54            /// Mutateurs ///
55            void setValue(const ValueType & value);
56
57            void set(const CAttribute& attr) ;
58            void set(const CAttributeTemplate& attr) ;
59            void reset(void) ;
60            void checkEmpty(void) const;
61
62
63            void setInheritedValue(const CAttributeTemplate& attr );
64            void setInheritedValue(const CAttribute& attr );
65            T getInheritedValue(void) const ;
66            bool hasInheritedValue(void) const;
67           
68            bool isEqual(const CAttribute& attr );
69
70            /// Destructeur ///
71            virtual ~CAttributeTemplate(void) { }
72
73            /// Operateur ///
74            CAttributeTemplate& operator=(const ValueType & value);
75
76            /// Autre ///
77            virtual StdString toString(void) const { return _toString();}
78            virtual void fromString(const StdString & str) { if (str==resetInheritanceStr) { reset(); _canInherite=false ;}  else _fromString(str);}
79//            virtual CAttributeTemplate* clone() const {}
80//            virtual void toBinary  (StdOStream & os) const;
81//            virtual void fromBinary(StdIStream & is);
82            virtual StdString dump(void) const { return _dump();}
83
84            virtual bool toBuffer  (CBufferOut& buffer) const { return _toBuffer(buffer);}
85            virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer); }
86//            virtual size_t size(void) const;
87            virtual void generateCInterface(ostream& oss,const string& className) ;
88            virtual void generateFortran2003Interface(ostream& oss,const string& className) ;
89            virtual void generateFortranInterfaceDeclaration_(ostream& oss,const string& className) ;
90            virtual void generateFortranInterfaceBody_(ostream& oss,const string& className) ;
91            virtual void generateFortranInterfaceDeclaration(ostream& oss,const string& className) ;
92            virtual void generateFortranInterfaceGetDeclaration_(ostream& oss,const string& className) ;
93            virtual void generateFortranInterfaceGetBody_(ostream& oss,const string& className) ;
94            virtual void generateFortranInterfaceGetDeclaration(ostream& oss,const string& className) ;
95//            virtual void generateFortranInterfaceIsDefinedDeclaration_(ostream& oss,const string& className) ;
96//            virtual void generateFortranInterfaceIsDefinedBody_(ostream& oss,const string& className) ;
97//            virtual void generateFortranInterfaceIsDefinedDeclaration(ostream& oss,const string& className) ;
98
99           static int show_TV_ttf_display_type ( const CAttributeTemplate<T>* attr)
100           {
101             int status ;
102             if (attr->isEmpty()) 
103             {
104               status = TV_ttf_add_row("State", TV_ttf_type_ascii_string,"(empty)") ;
105               if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
106               else return TV_ttf_format_ok_elide ;
107             }
108             else 
109             {
110               char tname[128] ;
111               char bname[128] = "ValueType" ;
112#ifdef __GNUC__
113               size_t size = sizeof(bname) ;
114               abi::__cxa_demangle(typeid(T).name(), bname, &size, &status) ;
115               if (status !=0) return TV_ttf_format_raw ;
116#endif
117               snprintf (tname, sizeof(tname), "%s", bname);
118               if (typeid(T)==typeid(string))
119                 status = TV_ttf_add_row("values", TV_ttf_type_ascii_string, ((string*)(attr->ptrValue))->c_str() );
120               else status = TV_ttf_add_row("values", tname, attr->ptrValue) ;
121               if (status != TV_ttf_ec_ok) return TV_ttf_format_raw ;
122               else return TV_ttf_format_ok_elide ;
123             }
124           }
125     
126           static int TV_ttf_display_type ( const CAttributeTemplate<T>* attr )
127           {
128             return show_TV_ttf_display_type (attr) ;
129           }
130
131
132         protected :
133
134            /// Constructeurs ///
135//            CAttributeTemplate(void); // Not implemented.
136         private :
137          bool isEqual_(const CAttributeTemplate& attr);
138          StdString _toString(void) const;
139          StdString _dump(void) const;
140          void _fromString(const StdString & str);
141          bool _toBuffer  (CBufferOut& buffer) const;
142          bool _fromBuffer(CBufferIn& buffer) ;
143
144          CType<T> inheritedValue ;
145      }; // class CAttribute
146
147#define macrotype(_TYPE_)\
148  template<> int CAttributeTemplate<_TYPE_>::TV_ttf_display_type( const CAttributeTemplate<_TYPE_>* attr ) \
149  {\
150    return show_TV_ttf_display_type (attr) ;\
151  }
152
153macrotype(double)
154macrotype(int)
155macrotype(bool)
156macrotype(string)
157//macrotype(CDate)
158//macrotype(CDuration)
159#undef macrotype
160
161   template <class T>  void FromBinary(StdIStream & is, T & obj);
162
163
164} // namespace xios
165
166#endif // __XIOS_CAttributeTemplate__
Note: See TracBrowser for help on using the repository browser.