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