source: XIOS/trunk/src/declare_attribute.hpp @ 539

Last change on this file since 539 was 527, checked in by rlacroix, 9 years ago

Make the variable typing stricter.

The type must now be one of:

  • bool
  • int or int32
  • int16
  • int64
  • float
  • double
  • string

WARNING: The variable type was previously not checked and using an unsupported type did not lead to any error message. Be aware that this change can make your existing configuration files invalid. However the adjustments required to adapt existing files should be minor.

  • 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: 8.4 KB
Line 
1#ifndef __XMLIO_DECLARE_ATTRIBUTE__
2#define __XMLIO_DECLARE_ATTRIBUTE__
3
4/// ///////////////////////////// Macros ///////////////////////////// ///
5
6#define DECLARE_ATTRIBUTE(type, name)                             \
7   class name##_attr : public CAttributeTemplate<type>            \
8   {                                                              \
9      public :                                                    \
10         name##_attr(void)                                          \
11            : CAttributeTemplate<type>                            \
12            (#name, *CAttributeMap::Current)                      \
13         { /* Ne rien faire de plus */ }                          \
14         type operator=(const type & value)                       \
15         { return (CAttributeTemplate<type>::operator=(value)); } \
16         virtual ~name##_attr(void)                                 \
17         { /* Ne rien faire de plus */ }                          \
18   } name;
19
20#define DECLARE_ARRAY(T_num, T_rank, name)                        \
21   class name##_attr : public CAttributeArray<T_num, T_rank>      \
22   {                                                              \
23      public :                                                    \
24         using CAttributeArray<T_num, T_rank>::operator = ;       \
25         name##_attr(void) : CAttributeArray<T_num, T_rank> (#name, *CAttributeMap::Current) {} \
26         virtual ~name##_attr(void) {}                            \
27   } name;
28   
29#define DECLARE_CLASS_ENUM(name)                                   \
30   class name##_attr : public CAttributeEnum<Enum_##name>          \
31   {                                                              \
32      public :                                                    \
33         name##_attr(void) : CAttributeEnum<Enum_##name>(#name, *CAttributeMap::Current) { } \
34         virtual ~name##_attr(void) {}                           \
35   } name;
36   
37#define DECLARE_ENUM2(name,arg1,arg2)                             \
38   class Enum_##name                                              \
39   {                                                              \
40     public:                                                      \
41     enum t_enum { arg1=0, arg2} ;                                \
42     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2 } ; return enumStr ; }   \
43     int getSize(void) const { return 2 ; }                       \
44   } ;                                                            \
45   DECLARE_CLASS_ENUM(name)
46   
47#define DECLARE_ENUM3(name,arg1,arg2,arg3)                             \
48   class Enum_##name                                              \
49   {                                                              \
50     public:                                                      \
51     enum t_enum { arg1=0, arg2, arg3} ;                                \
52     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3 } ; return enumStr ; }   \
53     int getSize(void) const { return 3 ; }                       \
54   } ;                                                            \
55   DECLARE_CLASS_ENUM(name)
56
57#define DECLARE_ENUM4(name,arg1,arg2,arg3,arg4)                             \
58   class Enum_##name                                              \
59   {                                                              \
60     public:                                                      \
61     enum t_enum { arg1=0, arg2, arg3,arg4} ;                                \
62     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3,#arg4 } ; return enumStr ; }   \
63     int getSize(void) const { return 4 ; }                       \
64   } ;                                                            \
65   DECLARE_CLASS_ENUM(name)
66
67#define DECLARE_ENUM5(name,arg1,arg2,arg3,arg4,arg5)                             \
68   class Enum_##name                                              \
69   {                                                              \
70     public:                                                      \
71     enum t_enum { arg1=0, arg2, arg3,arg4,arg5} ;                                \
72     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3,#arg4,#arg5 } ; return enumStr ; }   \
73     int getSize(void) const { return 5 ; }                       \
74   } ;                                                            \
75   DECLARE_CLASS_ENUM(name)
76
77#define DECLARE_ENUM6(name,arg1,arg2,arg3,arg4,arg5,arg6)                             \
78   class Enum_##name                                              \
79   {                                                              \
80     public:                                                      \
81     enum t_enum { arg1=0, arg2, arg3,arg4,arg5,arg6} ;                                \
82     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3,#arg4,#arg5,#arg6 } ; return enumStr ; }   \
83     int getSize(void) const { return 6 ; }                       \
84   } ;                                                            \
85   DECLARE_CLASS_ENUM(name)
86
87#define DECLARE_ENUM7(name,arg1,arg2,arg3,arg4,arg5,arg6,arg7)                             \
88   class Enum_##name                                              \
89   {                                                              \
90     public:                                                      \
91     enum t_enum { arg1=0, arg2, arg3,arg4,arg5,arg6,arg7} ;                                \
92     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3,#arg4,#arg5,#arg6,#arg7 } ; return enumStr ; }   \
93     int getSize(void) const { return 7 ; }                       \
94   } ;                                                            \
95   DECLARE_CLASS_ENUM(name)
96
97#define DECLARE_ENUM8(name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)                             \
98   class Enum_##name                                              \
99   {                                                              \
100     public:                                                      \
101     enum t_enum { arg1=0, arg2, arg3,arg4,arg5,arg6,arg7,arg8} ;                                \
102     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3,#arg4,#arg5,#arg6,#arg7,#arg8 } ; return enumStr ; }   \
103     int getSize(void) const { return 8 ; }                       \
104   } ;                                                            \
105   DECLARE_CLASS_ENUM(name)
106
107  #define DECLARE_ENUM9(name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)                             \
108   class Enum_##name                                              \
109   {                                                              \
110     public:                                                      \
111     enum t_enum { arg1=0, arg2, arg3,arg4,arg5,arg6,arg7,arg8,arg9} ;                                \
112     const char** getStr(void) const { static const char * enumStr[] = { #arg1, #arg2, #arg3,#arg4,#arg5,#arg6,#arg7,#arg8,#arg9 } ; return enumStr ; }   \
113     int getSize(void) const { return 9 ; }                       \
114   } ;                                                            \
115   DECLARE_CLASS_ENUM(name) 
116
117  #define DECLARE_TYPE(name)                                      \
118   class Enum_##name                                              \
119   {                                                              \
120     public:                                                      \
121     enum t_enum { t_bool=0, t_int16, t_int, t_int32, t_int64, t_float, t_double, t_string }; \
122     const char** getStr(void) const { static const char * enumStr[] = { "bool", "int16", "int", "int32", "int64", "float", "double", "string" }; return enumStr; } \
123     int getSize(void) const { return 8; }                        \
124   };                                                             \
125   DECLARE_CLASS_ENUM(name)
126
127#define BEGIN_DECLARE_ATTRIBUTE_MAP(type)                  \
128   class type##Attributes : public virtual CAttributeMap   \
129   {                                                       \
130      public :
131
132#define END_DECLARE_ATTRIBUTE_MAP(type)            \
133         type##Attributes (void) : CAttributeMap() \
134         { /* Ne rien faire de plus */ }           \
135         virtual ~type##Attributes (void)          \
136         { /* Ne rien faire de plus */ }           \
137   };
138
139#endif // __XMLIO_DECLARE_ATTRIBUTE__
Note: See TracBrowser for help on using the repository browser.