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