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