From 78cf5a4ccfe4e36f33230bb196aad34eb3cf89f7 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 20 Apr 2009 19:27:11 +0000 Subject: COMMON & TESTS: Added new constructor to Array, 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 --- common/array.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'common') 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 &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; } -- cgit v1.2.3