[6607] | 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 string dump(void) const { return _toString(); } |
---|
| 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(); } |
---|
| 46 | virtual bool isEmpty() const { return _isEmpty(); } |
---|
| 47 | virtual size_t size(void) const { return _size(); } |
---|
| 48 | |
---|
| 49 | void allocate(void) ; |
---|
| 50 | virtual void checkEmpty(void) const {return _checkEmpty();}; |
---|
| 51 | |
---|
| 52 | T* ptrValue ; |
---|
| 53 | bool empty ; |
---|
| 54 | |
---|
| 55 | friend class CType_ref<T> ; |
---|
| 56 | |
---|
| 57 | private : |
---|
| 58 | |
---|
| 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) ; |
---|
| 65 | bool _isEmpty() const ; |
---|
| 66 | void _checkEmpty(void) const; |
---|
| 67 | size_t _size(void) const ; |
---|
| 68 | |
---|
| 69 | } ; |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | template<typename T> class CType ; |
---|
| 73 | |
---|
| 74 | template <typename T> |
---|
| 75 | class CType_ref : public virtual CBaseType |
---|
| 76 | { |
---|
| 77 | public: |
---|
| 78 | |
---|
| 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) ; |
---|
| 94 | |
---|
| 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; |
---|
| 98 | operator T&() const; |
---|
| 99 | |
---|
| 100 | inline virtual CBaseType* clone(void) const { return _clone(); } |
---|
| 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(); } |
---|
| 108 | virtual bool isEmpty() const { return _isEmpty(); } |
---|
| 109 | virtual size_t size(void) const { return _size(); } |
---|
| 110 | |
---|
| 111 | void checkEmpty(void) const; |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | T mutable * ptrValue ; |
---|
| 115 | bool empty ; |
---|
| 116 | friend class CType<T> ; |
---|
| 117 | |
---|
| 118 | private : |
---|
| 119 | |
---|
| 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) ; |
---|
| 128 | bool _isEmpty() const ; |
---|
| 129 | size_t _size(void) const ; |
---|
| 130 | } ; |
---|
| 131 | |
---|
| 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); |
---|
| 138 | |
---|
| 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 | |
---|
| 154 | class CMessage ; |
---|
| 155 | |
---|
| 156 | template <typename T> |
---|
| 157 | CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type) ; |
---|
| 158 | |
---|
| 159 | template <typename T> |
---|
| 160 | CBufferOut& operator<<(CBufferOut& buffer, const CType_ref<T>& type) ; |
---|
| 161 | |
---|
| 162 | template <typename T> |
---|
| 163 | CBufferOut& operator<<(CBufferOut& buffer, const T& type) ; |
---|
| 164 | |
---|
| 165 | template <typename T> |
---|
| 166 | CBufferOut& operator<<(CBufferOut& buffer, T& type) ; |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | template <typename T> |
---|
| 170 | CBufferIn& operator>>(CBufferIn& buffer, CType<T>& type) ; |
---|
| 171 | |
---|
| 172 | template <typename T> |
---|
| 173 | CBufferIn& operator>>(CBufferIn& buffer, const CType_ref<T>& type) ; |
---|
| 174 | |
---|
| 175 | template <typename T> |
---|
| 176 | CBufferIn& operator>>(CBufferIn& buffer, T& type) ; |
---|
| 177 | |
---|
| 178 | /* |
---|
| 179 | template <typename T> |
---|
| 180 | CMessage& operator<<(CMessage& msg, const CType<T>& type) ; |
---|
| 181 | |
---|
| 182 | template <typename T> |
---|
| 183 | CMessage& operator<<(CMessage& msg, const CType_ref<T>& type) ; |
---|
| 184 | */ |
---|
| 185 | |
---|
| 186 | template <typename T> |
---|
| 187 | CMessage& operator<<(CMessage& msg, const T& type) ; |
---|
| 188 | |
---|
| 189 | template <typename T> |
---|
| 190 | CMessage& operator<<(CMessage& msg, T& type) ; |
---|
| 191 | |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | //#include "test_type_impl.hpp" |
---|
| 196 | //#include "test_type_specialisation.hpp" |
---|
| 197 | |
---|
| 198 | #endif |
---|
| 199 | |
---|