[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 ; |
---|
[748] | 15 | |
---|
| 16 | template <typename T> |
---|
[369] | 17 | class CType : public virtual CBaseType |
---|
[308] | 18 | { |
---|
| 19 | public: |
---|
[748] | 20 | |
---|
[308] | 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&() ; |
---|
[748] | 37 | operator const T&() const ; |
---|
| 38 | |
---|
[394] | 39 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
[369] | 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(); } |
---|
[748] | 45 | virtual bool isEmpty() const { return _isEmpty(); } |
---|
[369] | 46 | virtual size_t size(void) const { return _size(); } |
---|
[748] | 47 | |
---|
[369] | 48 | void allocate(void) ; |
---|
[1478] | 49 | virtual void checkEmpty(void) const {return _checkEmpty();}; |
---|
[748] | 50 | |
---|
[369] | 51 | T* ptrValue ; |
---|
| 52 | bool empty ; |
---|
[748] | 53 | |
---|
| 54 | friend class CType_ref<T> ; |
---|
| 55 | |
---|
[369] | 56 | private : |
---|
[748] | 57 | |
---|
[369] | 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) ; |
---|
[748] | 64 | bool _isEmpty() const ; |
---|
[1478] | 65 | void _checkEmpty(void) const; |
---|
[369] | 66 | size_t _size(void) const ; |
---|
[748] | 67 | |
---|
[369] | 68 | } ; |
---|
[308] | 69 | |
---|
[369] | 70 | |
---|
| 71 | template<typename T> class CType ; |
---|
[748] | 72 | |
---|
| 73 | template <typename T> |
---|
[369] | 74 | class CType_ref : public virtual CBaseType |
---|
| 75 | { |
---|
| 76 | public: |
---|
[748] | 77 | |
---|
[369] | 78 | CType_ref(void) ; |
---|
| 79 | CType_ref(T& val) ; |
---|
| 80 | CType_ref(CType<T>& type) ; |
---|
| 81 | CType_ref(const CType_ref& type) ; |
---|
| 82 | virtual ~CType_ref() {}; |
---|
| 83 | |
---|
| 84 | T& get(void) const; |
---|
| 85 | |
---|
| 86 | void set(const T& val) const ; |
---|
| 87 | void set(const CType<T>& val) const ; |
---|
| 88 | void set(const CType_ref& val) const ; |
---|
| 89 | |
---|
| 90 | void set_ref(T& val) ; |
---|
| 91 | void set_ref(CType<T>& val) ; |
---|
| 92 | void set_ref(const CType_ref& val) ; |
---|
[748] | 93 | |
---|
[369] | 94 | const CType_ref& operator = (T& val) const ; |
---|
| 95 | const CType_ref& operator = (CType<T>& val) const ; |
---|
| 96 | const CType_ref& operator = (const CType_ref& val) const; |
---|
[1158] | 97 | operator T&() const; |
---|
[369] | 98 | |
---|
[394] | 99 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
[369] | 100 | virtual void fromString(const string& str) { _fromString(str); } |
---|
| 101 | virtual void fromString(const string& str) const { _fromString(str); } |
---|
| 102 | virtual string toString(void) const { return _toString(); } |
---|
| 103 | virtual bool fromBuffer(CBufferIn& buffer) { return _fromBuffer(buffer) ; } |
---|
| 104 | virtual bool fromBuffer(CBufferIn& buffer) const { return _fromBuffer(buffer); } |
---|
| 105 | virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } |
---|
| 106 | virtual void reset(void) { _reset(); } |
---|
[748] | 107 | virtual bool isEmpty() const { return _isEmpty(); } |
---|
[369] | 108 | virtual size_t size(void) const { return _size(); } |
---|
| 109 | |
---|
| 110 | void checkEmpty(void) const; |
---|
| 111 | |
---|
[748] | 112 | |
---|
[369] | 113 | T mutable * ptrValue ; |
---|
| 114 | bool empty ; |
---|
| 115 | friend class CType<T> ; |
---|
[748] | 116 | |
---|
[369] | 117 | private : |
---|
[748] | 118 | |
---|
[369] | 119 | CType_ref* _clone(void) const; |
---|
| 120 | void _fromString(const string& str) ; |
---|
| 121 | void _fromString(const string& str) const; |
---|
| 122 | string _toString(void) const; |
---|
| 123 | bool _fromBuffer(CBufferIn& buffer) ; |
---|
| 124 | bool _fromBuffer(CBufferIn& buffer) const ; |
---|
| 125 | bool _toBuffer(CBufferOut& buffer) const; |
---|
| 126 | void _reset(void) ; |
---|
[748] | 127 | bool _isEmpty() const ; |
---|
[369] | 128 | size_t _size(void) const ; |
---|
[308] | 129 | } ; |
---|
[748] | 130 | |
---|
[1158] | 131 | template <typename T> bool operator==(const CType<T>& lhs, const T& rhs); |
---|
| 132 | template <typename T> bool operator==(const T& lhs, const CType<T>& rhs); |
---|
| 133 | template <typename T> bool operator==(const CType_ref<T>& lhs, const T& rhs); |
---|
| 134 | template <typename T> bool operator==(const T& lhs, const CType_ref<T>& rhs); |
---|
| 135 | template <typename T> bool operator==(const CType<T>& lhs, const CType<T>& rhs); |
---|
| 136 | template <typename T> bool operator==(const CType_ref<T>& lhs, const CType_ref<T>& rhs); |
---|
[748] | 137 | |
---|
[1158] | 138 | template <typename T> |
---|
| 139 | bool operator==(const CType_ref<T>& lhs, const CType<T>& rhs) |
---|
| 140 | { |
---|
| 141 | if ((lhs.isEmpty() && !rhs.isEmpty()) || (!lhs.isEmpty() && rhs.isEmpty())) return false; |
---|
| 142 | if (lhs.isEmpty() && rhs.isEmpty()) return true; |
---|
| 143 | return (*lhs.ptrValue == *rhs.ptrValue); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | template <typename T> |
---|
| 147 | bool operator==(const CType<T>& lhs, const CType_ref<T>& rhs) |
---|
| 148 | { |
---|
| 149 | return (rhs == lhs); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
[352] | 153 | class CMessage ; |
---|
[748] | 154 | |
---|
[352] | 155 | template <typename T> |
---|
| 156 | CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type) ; |
---|
| 157 | |
---|
| 158 | template <typename T> |
---|
[369] | 159 | CBufferOut& operator<<(CBufferOut& buffer, const CType_ref<T>& type) ; |
---|
[748] | 160 | |
---|
[352] | 161 | template <typename T> |
---|
| 162 | CBufferOut& operator<<(CBufferOut& buffer, const T& type) ; |
---|
[748] | 163 | |
---|
[352] | 164 | template <typename T> |
---|
[369] | 165 | CBufferOut& operator<<(CBufferOut& buffer, T& type) ; |
---|
| 166 | |
---|
| 167 | |
---|
[352] | 168 | template <typename T> |
---|
[369] | 169 | CBufferIn& operator>>(CBufferIn& buffer, CType<T>& type) ; |
---|
[352] | 170 | |
---|
[369] | 171 | template <typename T> |
---|
| 172 | CBufferIn& operator>>(CBufferIn& buffer, const CType_ref<T>& type) ; |
---|
[352] | 173 | |
---|
| 174 | template <typename T> |
---|
[369] | 175 | CBufferIn& operator>>(CBufferIn& buffer, T& type) ; |
---|
| 176 | |
---|
[401] | 177 | /* |
---|
[369] | 178 | template <typename T> |
---|
[352] | 179 | CMessage& operator<<(CMessage& msg, const CType<T>& type) ; |
---|
[369] | 180 | |
---|
[352] | 181 | template <typename T> |
---|
[369] | 182 | CMessage& operator<<(CMessage& msg, const CType_ref<T>& type) ; |
---|
[748] | 183 | */ |
---|
| 184 | |
---|
[352] | 185 | template <typename T> |
---|
| 186 | CMessage& operator<<(CMessage& msg, const T& type) ; |
---|
[369] | 187 | |
---|
[352] | 188 | template <typename T> |
---|
| 189 | CMessage& operator<<(CMessage& msg, T& type) ; |
---|
[369] | 190 | |
---|
[308] | 191 | } |
---|
| 192 | |
---|
| 193 | |
---|
[369] | 194 | //#include "test_type_impl.hpp" |
---|
| 195 | //#include "test_type_specialisation.hpp" |
---|
[352] | 196 | |
---|
[308] | 197 | #endif |
---|
[369] | 198 | |
---|