diff options
| author | Max Horn | 2009-04-20 19:27:11 +0000 |
|---|---|---|
| committer | Max Horn | 2009-04-20 19:27:11 +0000 |
| commit | 78cf5a4ccfe4e36f33230bb196aad34eb3cf89f7 (patch) | |
| tree | 15f038e525bc9a7d0900f339e558ea43e53e1856 /common | |
| parent | faa911794953679a1fff24999878f79612dfc7f3 (diff) | |
| download | scummvm-rg350-78cf5a4ccfe4e36f33230bb196aad34eb3cf89f7.tar.gz scummvm-rg350-78cf5a4ccfe4e36f33230bb196aad34eb3cf89f7.tar.bz2 scummvm-rg350-78cf5a4ccfe4e36f33230bb196aad34eb3cf89f7.zip | |
COMMON & TESTS: Added new constructor to Array<T>, namely Array(const T* data, int n), which makes it possible to clone a regular array into a Common::Array; added a unit test for that and slightly extended existing Common::Array unit tests
svn-id: r40027
Diffstat (limited to 'common')
| -rw-r--r-- | common/array.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/common/array.h b/common/array.h index 693c024d11..2db0ed2a8b 100644 --- a/common/array.h +++ b/common/array.h @@ -46,12 +46,20 @@ public: public: Array() : _capacity(0), _size(0), _storage(0) {} Array(const Array<T> &array) : _capacity(0), _size(0), _storage(0) { - _size = array._size; - _capacity = _size + 32; + _capacity = _size = array._size; _storage = new T[_capacity]; copy(array._storage, array._storage + _size, _storage); } + /** + * Construct an array by copying data from a regular array. + */ + Array(const T *data, int n) { + _capacity = _size = n; + _storage = new T[_capacity]; + copy(data, data + _size, _storage); + } + ~Array() { delete[] _storage; } |
