Changeset 1285
- Timestamp:
- Apr 24, 2012, 1:07:35 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/array.h
r1269 r1285 31 31 inline ~Array() { delete[] m_data; } 32 32 33 Array(Array const& that) : m_data(0), m_count(0), m_reserved(0) 34 { 35 Reserve(that.m_reserved); 36 memcpy(m_data, that.m_data, m_count * sizeof(Element)); 37 m_count = that.m_count; 38 } 39 40 Array& operator=(Array const& that) 41 { 42 m_data = 0; 43 m_count = 0; 44 m_reserved = 0; 45 Reserve(that.m_reserved); 46 memcpy(m_data, that.m_data, that.m_count * sizeof(Element)); 47 m_count = that.m_count; 48 return *this; 49 } 50 33 51 inline Element& operator[](int n) 34 52 { … … 118 136 inline ~Array() { delete[] m_data; } 119 137 138 Array(Array const& that) : m_data(0), m_count(0), m_reserved(0) 139 { 140 Reserve(that.m_reserved); 141 memcpy(m_data, that.m_data, m_count * sizeof(Element)); 142 m_count = that.m_count; 143 } 144 145 Array& operator=(Array const& that) 146 { 147 m_data = 0; 148 m_count = 0; 149 m_reserved = 0; 150 Reserve(that.m_reserved); 151 memcpy(m_data, that.m_data, that.m_count * sizeof(Element)); 152 m_count = that.m_count; 153 return *this; 154 } 155 120 156 inline Element& operator[](int n) 121 157 { … … 198 234 { 199 235 public: 236 typedef T1 Element; 237 200 238 inline Array() : m_data(0), m_count(0), m_reserved(0) {} 201 239 inline ~Array() { delete[] m_data; } 202 240 203 inline T1& operator[](int n) 204 { 205 return m_data[n]; 206 } 207 208 inline T1 const& operator[](int n) const 241 Array(Array const& that) : m_data(0), m_count(0), m_reserved(0) 242 { 243 Reserve(that.m_reserved); 244 memcpy(m_data, that.m_data, m_count * sizeof(Element)); 245 m_count = that.m_count; 246 } 247 248 Array& operator=(Array const& that) 249 { 250 m_data = 0; 251 m_count = 0; 252 m_reserved = 0; 253 Reserve(that.m_reserved); 254 memcpy(m_data, that.m_data, that.m_count * sizeof(Element)); 255 m_count = that.m_count; 256 return *this; 257 } 258 259 inline Element& operator[](int n) 260 { 261 return m_data[n]; 262 } 263 264 inline Element const& operator[](int n) const 209 265 { 210 266 return m_data[n]; … … 248 304 return; 249 305 250 T1 *tmp = new T1[count];306 Element *tmp = new Element[count]; 251 307 if (m_data) 252 308 { 253 memcpy(tmp, m_data, m_count * sizeof( T1));309 memcpy(tmp, m_data, m_count * sizeof(Element)); 254 310 delete[] m_data; 255 311 } … … 259 315 260 316 inline int Count() const { return m_count; } 261 inline int Bytes() const { return m_count * sizeof( T1); }317 inline int Bytes() const { return m_count * sizeof(Element); } 262 318 263 319 private: 264 T1*m_data;320 Element *m_data; 265 321 int m_count, m_reserved; 266 322 };
Note: See TracChangeset
for help on using the changeset viewer.