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

Last change on this file since 1960 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
RevLine 
[591]1#ifndef __XIOS_CAttributeTemplate__
2#define __XIOS_CAttributeTemplate__
[219]3
4/// boost headers ///
5#include <boost/lexical_cast.hpp>
6
[591]7/// XIOS headers ///
8#include "xios_spl.hpp"
[219]9#include "exception.hpp"
10#include "attribute.hpp"
[300]11#include "buffer_in.hpp"
12#include "buffer_out.hpp"
[369]13#include "type.hpp"
[1875]14#include "tv_data_display.h"
[219]15
[1875]16#ifdef __GNUC__
17#include <typeinfo>
18#include <cxxabi.h>
19#endif
20
[335]21namespace xios
[219]22{
23      /// ////////////////////// Déclarations ////////////////////// ///
[1158]24  /*!
25    \class CAttributeTemplate
26    The class implements attribute of some basic types
27  */
[1875]28       template <class T>
[778]29         class CAttributeTemplate : public CAttribute, public CType<T>
[219]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);
[369]45//            CAttributeTemplate(const CAttribute & attribut) throw (CException);
46//            CAttributeTemplate(const CAttribute * const attribut); // Not implemented.
[219]47
48          public :
49
50            /// Accesseur ///
[354]51            ValueType getValue(void) const;
[369]52//            ValueType* getRef(void) ;
[219]53
54            /// Mutateurs ///
[354]55            void setValue(const ValueType & value);
[775]56
[369]57            void set(const CAttribute& attr) ;
58            void set(const CAttributeTemplate& attr) ;
[460]59            void reset(void) ;
[1478]60            void checkEmpty(void) const;
[445]61
[1478]62
[445]63            void setInheritedValue(const CAttributeTemplate& attr );
64            void setInheritedValue(const CAttribute& attr );
65            T getInheritedValue(void) const ;
66            bool hasInheritedValue(void) const;
[1219]67           
[1158]68            bool isEqual(const CAttribute& attr );
69
[219]70            /// Destructeur ///
[369]71            virtual ~CAttributeTemplate(void) { }
[219]72
73            /// Operateur ///
[369]74            CAttributeTemplate& operator=(const ValueType & value);
[219]75
76            /// Autre ///
[369]77            virtual StdString toString(void) const { return _toString();}
[1158]78            virtual void fromString(const StdString & str) { if (str==resetInheritanceStr) { reset(); _canInherite=false ;}  else _fromString(str);}
[369]79//            virtual CAttributeTemplate* clone() const {}
80//            virtual void toBinary  (StdOStream & os) const;
[775]81//            virtual void fromBinary(StdIStream & is);
[1622]82            virtual StdString dump(void) const { return _dump();}
[219]83
[775]84            virtual bool toBuffer  (CBufferOut& buffer) const { return _toBuffer(buffer);}
85            virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer); }
[369]86//            virtual size_t size(void) const;
[313]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) ;
[432]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) ;
[300]98
[1875]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           }
[775]130
[1875]131
[219]132         protected :
133
134            /// Constructeurs ///
[369]135//            CAttributeTemplate(void); // Not implemented.
136         private :
[1219]137          bool isEqual_(const CAttributeTemplate& attr);
[369]138          StdString _toString(void) const;
[1622]139          StdString _dump(void) const;
[369]140          void _fromString(const StdString & str);
141          bool _toBuffer  (CBufferOut& buffer) const;
142          bool _fromBuffer(CBufferIn& buffer) ;
[775]143
[445]144          CType<T> inheritedValue ;
[775]145      }; // class CAttribute
146
[1875]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  }
[775]152
[1875]153macrotype(double)
154macrotype(int)
155macrotype(bool)
156macrotype(string)
157//macrotype(CDate)
158//macrotype(CDuration)
159#undef macrotype
160
[219]161   template <class T>  void FromBinary(StdIStream & is, T & obj);
[775]162
[1875]163
[335]164} // namespace xios
[219]165
[591]166#endif // __XIOS_CAttributeTemplate__
Note: See TracBrowser for help on using the repository browser.