From 0fe3a0c676bfcf773c15b76e4e0fc3e642f82f58 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 17 Jul 2002 17:22:48 +0000 Subject: added copy constructo and assignment operator for List template svn-id: r4582 --- gui/util.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'gui') 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() : _capacity(0), _size(0), _data(0) {} List(const List& 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() @@ -69,9 +73,30 @@ public: return _data[idx]; } + List& operator =(const List& 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) -- cgit v1.2.3