diff options
author | Max Horn | 2002-07-17 17:22:48 +0000 |
---|---|---|
committer | Max Horn | 2002-07-17 17:22:48 +0000 |
commit | 0fe3a0c676bfcf773c15b76e4e0fc3e642f82f58 (patch) | |
tree | 2ce915682a1999219d0a38d3e2a88a8de3b01a6b /gui | |
parent | 0e141368b05ec69dd694460b19e04b315cb99f9b (diff) | |
download | scummvm-rg350-0fe3a0c676bfcf773c15b76e4e0fc3e642f82f58.tar.gz scummvm-rg350-0fe3a0c676bfcf773c15b76e4e0fc3e642f82f58.tar.bz2 scummvm-rg350-0fe3a0c676bfcf773c15b76e4e0fc3e642f82f58.zip |
added copy constructo and assignment operator for List<T> template
svn-id: r4582
Diffstat (limited to 'gui')
-rw-r--r-- | gui/util.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/gui/util.h b/gui/util.h index 4509a0bcb3..4340286af1 100644 --- a/gui/util.h +++ b/gui/util.h @@ -40,7 +40,11 @@ public: List<T>() : _capacity(0), _size(0), _data(0) {} List<T>(const List<T>& list) : _capacity(0), _size(0), _data(0) { - error("EEEEK! List copy constructor called"); + _size = list._size; + _capacity = _size + 32; + _data = new T[_capacity]; + for (int i = 0; i < _size; i++) + _data[i] = list._data[i]; } ~List<T>() @@ -69,9 +73,30 @@ public: return _data[idx]; } + List<T>& operator =(const List<T>& list) + { + if (_data) + delete [] _data; + _size = list._size; + _capacity = _size + 32; + _data = new T[_capacity]; + for (int i = 0; i < _size; i++) + _data[i] = list._data[i]; + + return *this; + } + int size() const { return _size; } - void clear() { _size = 0; } + void clear() + { + if (_data) { + delete [] _data; + _data = 0; + } + _size = 0; + _capacity = 0; + } protected: void ensureCapacity(int new_len) |