aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/list.h19
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)