diff options
author | Max Horn | 2002-10-15 15:32:32 +0000 |
---|---|---|
committer | Max Horn | 2002-10-15 15:32:32 +0000 |
commit | d8c26a61aef379c9ad43d4f5cc101ee1ed22440b (patch) | |
tree | 843c3d975fbe28d21978053de89dba8663648f00 | |
parent | bd15755b17e0ed616114db52821e0fce58f0a29e (diff) | |
download | scummvm-rg350-d8c26a61aef379c9ad43d4f5cc101ee1ed22440b.tar.gz scummvm-rg350-d8c26a61aef379c9ad43d4f5cc101ee1ed22440b.tar.bz2 scummvm-rg350-d8c26a61aef379c9ad43d4f5cc101ee1ed22440b.zip |
added insert_at method to List template
svn-id: r5153
-rw-r--r-- | common/list.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/common/list.h b/common/list.h index 87e8b5ab34..f5f3e4967a 100644 --- a/common/list.h +++ b/common/list.h @@ -49,12 +49,27 @@ public: delete [] _data; } - void push_back(const T& str) + void push_back(const T& element) { ensureCapacity(_size + 1); - _data[_size++] = str; + _data[_size++] = element; } + void insert_at(int idx, const T& element) + { + assert(idx >= 0 && idx <= _size); + ensureCapacity(_size + 1); + // The following loop is not efficient if you can just memcpy things around. + // e.g. if you have a list of ints. But for real objects (String...), memcpy + // is *not* usually a good idea! + for (int i = _size; i > idx; i--) { + _data[i] = _data[i-1]; + } + _data[idx] = element; + _size++; + } + + // TODO: insert, remove, ... T& operator [](int idx) |