Changeset 748
- Timestamp:
- 10/21/15 13:40:57 (8 years ago)
- Location:
- XIOS/trunk/src/type
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/type/type.hpp
r591 r748 13 13 14 14 template <typename T> class CType_ref ; 15 16 template <typename T> 15 16 template <typename T> 17 17 class CType : public virtual CBaseType 18 18 { 19 19 public: 20 20 21 21 CType(void) ; 22 22 CType(const T& val) ; … … 35 35 CType& operator = (const CType_ref<T>& val) ; 36 36 operator T&() ; 37 37 operator const T&() const ; 38 38 39 inline virtual CBaseType* clone(void) const { return _clone(); } 39 40 virtual void fromString(const string& str) { _fromString(str); } … … 42 43 virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } 43 44 virtual void reset(void) { _reset(); } 44 virtual bool isEmpty() const { return _isEmpty(); } 45 virtual bool isEmpty() const { return _isEmpty(); } 45 46 virtual size_t size(void) const { return _size(); } 46 47 47 48 void allocate(void) ; 48 49 void checkEmpty(void) const; 49 50 50 51 T* ptrValue ; 51 52 bool empty ; 52 53 friend class CType_ref<T> ; 54 53 54 friend class CType_ref<T> ; 55 55 56 private : 56 57 57 58 CType* _clone(void) const; 58 59 void _fromString(const string& str) ; … … 61 62 bool _toBuffer(CBufferOut& buffer) const; 62 63 void _reset(void) ; 63 bool _isEmpty() const ; 64 bool _isEmpty() const ; 64 65 size_t _size(void) const ; 65 66 66 67 } ; 67 68 68 69 69 70 template<typename T> class CType ; 70 71 template <typename T> 71 72 template <typename T> 72 73 class CType_ref : public virtual CBaseType 73 74 { 74 75 public: 75 76 76 77 CType_ref(void) ; 77 78 CType_ref(T& val) ; … … 89 90 void set_ref(CType<T>& val) ; 90 91 void set_ref(const CType_ref& val) ; 91 92 92 93 const CType_ref& operator = (T& val) const ; 93 94 const CType_ref& operator = (CType<T>& val) const ; … … 103 104 virtual bool toBuffer(CBufferOut& buffer) const { return _toBuffer(buffer); } 104 105 virtual void reset(void) { _reset(); } 105 virtual bool isEmpty() const { return _isEmpty(); } 106 virtual bool isEmpty() const { return _isEmpty(); } 106 107 virtual size_t size(void) const { return _size(); } 107 108 108 109 void checkEmpty(void) const; 109 110 110 111 111 112 T mutable * ptrValue ; 112 113 bool empty ; 113 114 friend class CType<T> ; 114 115 115 116 private : 116 117 117 118 CType_ref* _clone(void) const; 118 119 void _fromString(const string& str) ; … … 123 124 bool _toBuffer(CBufferOut& buffer) const; 124 125 void _reset(void) ; 125 bool _isEmpty() const ; 126 bool _isEmpty() const ; 126 127 size_t _size(void) const ; 127 128 } ; 128 129 129 130 130 131 class CMessage ; 131 132 132 133 template <typename T> 133 134 CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type) ; … … 135 136 template <typename T> 136 137 CBufferOut& operator<<(CBufferOut& buffer, const CType_ref<T>& type) ; 137 138 138 139 template <typename T> 139 140 CBufferOut& operator<<(CBufferOut& buffer, const T& type) ; 140 141 141 142 template <typename T> 142 143 CBufferOut& operator<<(CBufferOut& buffer, T& type) ; … … 158 159 template <typename T> 159 160 CMessage& operator<<(CMessage& msg, const CType_ref<T>& type) ; 160 */ 161 161 */ 162 162 163 template <typename T> 163 164 CMessage& operator<<(CMessage& msg, const T& type) ; -
XIOS/trunk/src/type/type_impl.hpp
r680 r748 13 13 namespace xios 14 14 { 15 15 16 16 using namespace std; 17 17 18 18 template <typename T> 19 19 CType<T>::CType(void) … … 21 21 empty=true ; 22 22 } 23 23 24 24 template <typename T> 25 25 CType<T>::CType(const T& val) … … 28 28 set(val) ; 29 29 } 30 30 31 31 template <typename T> 32 32 CType<T>::CType(const CType<T>& type) … … 41 41 empty=true ; 42 42 set(type) ; 43 } 44 43 } 44 45 45 template <typename T> 46 46 void CType<T>::set(const T& val) 47 47 { 48 if (empty) 49 { 48 if (empty) 49 { 50 50 ptrValue = new T(val) ; 51 51 empty=false ; … … 61 61 { 62 62 if (empty) 63 { 63 { 64 64 ptrValue = new T(*type.ptrValue) ; 65 65 empty=false ; … … 76 76 { 77 77 if (empty) 78 { 78 { 79 79 ptrValue = new T(*type.ptrValue) ; 80 80 empty=false ; … … 97 97 return *ptrValue ; 98 98 } 99 99 100 100 template <typename T> 101 101 CType<T>& CType<T>::operator = (const T& val) … … 104 104 return *this ; 105 105 } 106 106 107 107 template <typename T> 108 108 CType<T>& CType<T>::operator = (const CType<T>& type) … … 111 111 return *this ; 112 112 } 113 113 114 114 template <typename T> 115 115 CType<T>& CType<T>::operator = (const CType_ref<T>& type) … … 118 118 return *this ; 119 119 } 120 120 121 121 template <typename T> 122 122 CType<T>::operator T&() 123 { 124 checkEmpty(); 125 return *ptrValue ; 126 } 127 128 template <typename T> 129 CType<T>::operator const T&() const 123 130 { 124 131 checkEmpty(); … … 133 140 } 134 141 135 142 136 143 template <typename T> 137 144 void CType<T>::_fromString(const string& str) … … 147 154 return sizeof(T) ; 148 155 } 149 156 150 157 template <typename T> 151 158 bool CType<T>::_isEmpty(void) const … … 153 160 return empty ; 154 161 } 155 162 156 163 template <typename T> 157 164 string CType<T>::_toString(void) const … … 162 169 return oss.str() ; 163 170 } 164 171 165 172 template <typename T> 166 173 bool CType<T>::_toBuffer(CBufferOut& buffer) const … … 169 176 return buffer.put(*ptrValue) ; 170 177 } 171 178 172 179 template <typename T> 173 180 bool CType<T>::_fromBuffer(CBufferIn& buffer) … … 176 183 return buffer.get(*ptrValue) ; 177 184 } 178 185 179 186 180 187 template <typename T> 181 188 void CType<T>::allocate(void) 182 189 { 183 if (empty) 190 if (empty) 184 191 { 185 192 ptrValue = new T ; … … 187 194 } 188 195 } 189 196 190 197 template <typename T> 191 198 void CType<T>::_reset(void) 192 199 { 193 if (!empty) 200 if (!empty) 194 201 { 195 202 delete ptrValue ; … … 197 204 } 198 205 } 199 206 200 207 template <typename T> 201 208 void CType<T>::checkEmpty(void) const 202 209 { 203 210 if (empty) ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << "Data is not initialized") ; 204 } 205 206 211 } 212 213 207 214 template <typename T> 208 215 CBufferOut& operator<<(CBufferOut& buffer, const CType<T>& type)
Note: See TracChangeset
for help on using the changeset viewer.