[308] | 1 | #ifndef __XIOS_TYPE__ |
---|
| 2 | #define __XIOS_TYPE__ |
---|
| 3 | |
---|
[591] | 4 | #include "xios_spl.hpp" |
---|
[308] | 5 | #include "exception.hpp" |
---|
| 6 | #include "buffer_in.hpp" |
---|
| 7 | #include "buffer_out.hpp" |
---|
| 8 | #include "base_type.hpp" |
---|
| 9 | |
---|
| 10 | |
---|
[335] | 11 | namespace xios |
---|
[308] | 12 | { |
---|
| 13 | |
---|
[369] | 14 | template <typename T> class CType_ref ; |
---|
| 15 | |
---|
[308] | 16 | template <typename T> |
---|
[369] | 17 | class CType : public virtual CBaseType |
---|
[308] | 18 | { |
---|
| 19 | public: |
---|
| 20 | |
---|
| 21 | CType(void) ; |
---|
| 22 | CType(const T& val) ; |
---|
| 23 | CType(const CType& type) ; |
---|
[369] | 24 | CType(const CType_ref<T>& type) ; |
---|
| 25 | virtual ~CType() { _reset() ; } |
---|
[308] | 26 | |
---|
[369] | 27 | T& get(void) ; |
---|
| 28 | const T& get(void) const; |
---|
[308] | 29 | |
---|
[369] | 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&() ; |
---|
[308] | 37 | |
---|
[394] | 38 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
[369] | 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(); } |
---|
[308] | 46 | |
---|
[369] | 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 | } ; |
---|
[308] | 67 | |
---|
[369] | 68 | |
---|
| 69 | template<typename T> class CType ; |
---|
[308] | 70 | |
---|
[369] | 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 | |
---|
[394] | 97 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
[369] | 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 ; |
---|
[308] | 127 | } ; |
---|
[369] | 128 | |
---|
| 129 | |
---|
[352] | 130 | class CMessage ; |
---|
| 131 | |
---|
| 132 | template <typename T> |
---|
| 133 | CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type) ; |
---|
| 134 | |
---|
| 135 | template <typename T> |
---|
[369] | 136 | CBufferOut& operator<<(CBufferOut& buffer, const CType_ref<T>& type) ; |
---|
[352] | 137 | |
---|
| 138 | template <typename T> |
---|
| 139 | CBufferOut& operator<<(CBufferOut& buffer, const T& type) ; |
---|
| 140 | |
---|
| 141 | template <typename T> |
---|
[369] | 142 | CBufferOut& operator<<(CBufferOut& buffer, T& type) ; |
---|
| 143 | |
---|
| 144 | |
---|
[352] | 145 | template <typename T> |
---|
[369] | 146 | CBufferIn& operator>>(CBufferIn& buffer, CType<T>& type) ; |
---|
[352] | 147 | |
---|
[369] | 148 | template <typename T> |
---|
| 149 | CBufferIn& operator>>(CBufferIn& buffer, const CType_ref<T>& type) ; |
---|
[352] | 150 | |
---|
| 151 | template <typename T> |
---|
[369] | 152 | CBufferIn& operator>>(CBufferIn& buffer, T& type) ; |
---|
| 153 | |
---|
[401] | 154 | /* |
---|
[369] | 155 | template <typename T> |
---|
[352] | 156 | CMessage& operator<<(CMessage& msg, const CType<T>& type) ; |
---|
[369] | 157 | |
---|
[352] | 158 | template <typename T> |
---|
[369] | 159 | CMessage& operator<<(CMessage& msg, const CType_ref<T>& type) ; |
---|
[401] | 160 | */ |
---|
[352] | 161 | |
---|
| 162 | template <typename T> |
---|
| 163 | CMessage& operator<<(CMessage& msg, const T& type) ; |
---|
[369] | 164 | |
---|
[352] | 165 | template <typename T> |
---|
| 166 | CMessage& operator<<(CMessage& msg, T& type) ; |
---|
[369] | 167 | |
---|
[308] | 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
[369] | 171 | //#include "test_type_impl.hpp" |
---|
| 172 | //#include "test_type_specialisation.hpp" |
---|
[352] | 173 | |
---|
[308] | 174 | #endif |
---|
[369] | 175 | |
---|