1 | #ifndef __XIOS_ENUM__ |
---|
2 | #define __XIOS_ENUM__ |
---|
3 | |
---|
4 | #include "xios_spl.hpp" |
---|
5 | #include "exception.hpp" |
---|
6 | #include "buffer_in.hpp" |
---|
7 | #include "buffer_out.hpp" |
---|
8 | #include "base_type.hpp" |
---|
9 | #include "message.hpp" |
---|
10 | |
---|
11 | #define __INLINE__ inline |
---|
12 | |
---|
13 | |
---|
14 | namespace xios |
---|
15 | { |
---|
16 | class CEnumBase |
---|
17 | { |
---|
18 | } ; |
---|
19 | |
---|
20 | template <typename T> class CEnum_ref ; |
---|
21 | |
---|
22 | template <typename T> |
---|
23 | class CEnum : public virtual CBaseType, public T |
---|
24 | { |
---|
25 | public: |
---|
26 | typedef typename T::t_enum T_enum ; |
---|
27 | CEnum(void) ; |
---|
28 | __INLINE__ CEnum(const T_enum& val) ; |
---|
29 | __INLINE__ CEnum(const CEnum& type) ; |
---|
30 | __INLINE__ CEnum(const CEnum_ref<T>& type) ; |
---|
31 | virtual ~CEnum() { _reset() ; } |
---|
32 | |
---|
33 | __INLINE__ T_enum& get(void) ; |
---|
34 | __INLINE__ const T_enum& get(void) const; |
---|
35 | |
---|
36 | __INLINE__ void set(const T_enum& val) ; |
---|
37 | __INLINE__ void set(const CEnum& val) ; |
---|
38 | __INLINE__ void set(const CEnum_ref<T>& val) ; |
---|
39 | __INLINE__ CEnum& operator = (const T_enum& val) ; |
---|
40 | __INLINE__ CEnum& operator = (const CEnum& val) ; |
---|
41 | __INLINE__ CEnum& operator = (const CEnum_ref<T>& val) ; |
---|
42 | __INLINE__ operator T_enum&() ; |
---|
43 | |
---|
44 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
45 | virtual void fromString(const string& str) { _fromString(str); } |
---|
46 | virtual string toString(void) const { return _toString(); } |
---|
47 | virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer) ; } |
---|
48 | virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } |
---|
49 | virtual void reset(void) { _reset(); } |
---|
50 | virtual bool isEmpty() const { return _isEmpty(); } |
---|
51 | virtual size_t size(void) const { return _size(); } |
---|
52 | |
---|
53 | __INLINE__ void allocate(void) ; |
---|
54 | __INLINE__ void checkEmpty(void) const; |
---|
55 | |
---|
56 | T_enum* ptrValue ; |
---|
57 | bool empty ; |
---|
58 | |
---|
59 | friend class CEnum_ref<T> ; |
---|
60 | |
---|
61 | private : |
---|
62 | |
---|
63 | __INLINE__ CEnum* _clone(void) const; |
---|
64 | __INLINE__ void _fromString(const string& str) ; |
---|
65 | __INLINE__ string _toString(void) const; |
---|
66 | __INLINE__ bool _fromBuffer(CBufferIn& buffer) ; |
---|
67 | __INLINE__ bool _toBuffer(CBufferOut& buffer) const; |
---|
68 | __INLINE__ void _reset(void) ; |
---|
69 | __INLINE__ bool _isEmpty() const ; |
---|
70 | __INLINE__ size_t _size(void) const ; |
---|
71 | |
---|
72 | } ; |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | template <typename T> |
---|
77 | class CEnum_ref : public virtual CBaseType, public T |
---|
78 | { |
---|
79 | public: |
---|
80 | |
---|
81 | typedef typename T::t_enum T_enum ; |
---|
82 | __INLINE__ CEnum_ref(void) ; |
---|
83 | __INLINE__ CEnum_ref(T_enum& val) ; |
---|
84 | __INLINE__ CEnum_ref(CEnum<T>& type) ; |
---|
85 | __INLINE__ CEnum_ref(const CEnum_ref& type) ; |
---|
86 | virtual ~CEnum_ref() {}; |
---|
87 | |
---|
88 | __INLINE__ T_enum& get(void) const; |
---|
89 | |
---|
90 | __INLINE__ void set(const T_enum& val) const ; |
---|
91 | __INLINE__ void set(const CEnum<T>& val) const ; |
---|
92 | __INLINE__ void set(const CEnum_ref& val) const ; |
---|
93 | |
---|
94 | __INLINE__ void set_ref(T_enum& val) ; |
---|
95 | __INLINE__ void set_ref(CEnum<T>& val) ; |
---|
96 | __INLINE__ void set_ref(const CEnum_ref& val) ; |
---|
97 | |
---|
98 | __INLINE__ const CEnum_ref& operator = (T_enum& val) const ; |
---|
99 | __INLINE__ const CEnum_ref& operator = (CEnum<T>& val) const ; |
---|
100 | __INLINE__ const CEnum_ref& operator = (const CEnum_ref& val) const; |
---|
101 | __INLINE__ operator T_enum&() const; |
---|
102 | bool operator == (const CEnum_ref &other) {return this->get()==other.get() ;} |
---|
103 | |
---|
104 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
105 | virtual void fromString(const string& str) { _fromString(str); } |
---|
106 | virtual void fromString(const string& str) const { _fromString(str); } |
---|
107 | virtual string toString(void) const { return _toString(); } |
---|
108 | virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer) ; } |
---|
109 | virtual bool fromBuffer(CBufferIn& buffer) const { return _fromBuffer(buffer); } |
---|
110 | virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } |
---|
111 | virtual void reset(void) { _reset(); } |
---|
112 | virtual bool isEmpty() const { return _isEmpty(); } |
---|
113 | virtual size_t size(void) const { return _size(); } |
---|
114 | |
---|
115 | __INLINE__ void checkEmpty(void) const; |
---|
116 | |
---|
117 | |
---|
118 | T_enum mutable * ptrValue ; |
---|
119 | bool empty ; |
---|
120 | friend class CEnum<T> ; |
---|
121 | |
---|
122 | private : |
---|
123 | |
---|
124 | __INLINE__ CEnum_ref* _clone(void) const; |
---|
125 | __INLINE__ void _fromString(const string& str) ; |
---|
126 | __INLINE__ void _fromString(const string& str) const; |
---|
127 | __INLINE__ string _toString(void) const; |
---|
128 | __INLINE__ bool _fromBuffer(CBufferIn& buffer) ; |
---|
129 | __INLINE__ bool _fromBuffer(CBufferIn& buffer) const ; |
---|
130 | __INLINE__ bool _toBuffer(CBufferOut& buffer) const; |
---|
131 | __INLINE__ void _reset(void) ; |
---|
132 | __INLINE__ bool _isEmpty() const ; |
---|
133 | __INLINE__ size_t _size(void) const ; |
---|
134 | } ; |
---|
135 | |
---|
136 | template <typename T> __INLINE__ CBufferOut& operator<<(CBufferOut& buffer, const CEnum<T>& type) ; |
---|
137 | template <typename T> __INLINE__ CBufferOut& operator<<(CBufferOut& buffer, const typename T::t_enum & type) ; |
---|
138 | template <typename T> __INLINE__ CBufferIn& operator>>(CBufferIn& buffer, CEnum<T>& type) ; |
---|
139 | // template <typename T> __INLINE__ CMessage& operator<<(CMessage& msg, const CEnum<T>& type) ; |
---|
140 | template <typename T> __INLINE__ CMessage& operator<<(CMessage& msg, const typename T::t_enum & type) ; |
---|
141 | |
---|
142 | template <typename T> __INLINE__ CBufferOut& operator<<(CBufferOut& buffer, const CEnum<T>& type) ; |
---|
143 | template <typename T> __INLINE__ CBufferOut& operator<<(CBufferOut& buffer, const typename T::t_enum & type); |
---|
144 | template <typename T> __INLINE__ CBufferIn& operator>>(CBufferIn& buffer, CEnum<T>& type); |
---|
145 | // template <typename T> __INLINE__ CMessage& operator<<(CMessage& msg, const CEnum<T>& type); |
---|
146 | template <typename T> __INLINE__ CMessage& operator<<(CMessage& msg, const typename T::t_enum & type); |
---|
147 | } |
---|
148 | |
---|
149 | # ifdef __INLINE__ |
---|
150 | # include "enum_impl.hpp" |
---|
151 | # include "enum_ref_impl.hpp" |
---|
152 | # endif |
---|
153 | |
---|
154 | #endif |
---|