Index: include/core/SkTArray.h |
=================================================================== |
--- include/core/SkTArray.h (revision 2287) |
+++ include/core/SkTArray.h (working copy) |
@@ -246,6 +246,16 @@ |
} |
/** |
+ * Version of above that uses a copy constructor to initialize the new item |
+ */ |
+ T& push_back(const T& t) { |
+ checkRealloc(1); |
+ new ((char*)fMemArray+sizeof(T)*fCount) T(t); |
+ ++fCount; |
+ return fItemArray[fCount-1]; |
+ } |
+ |
+ /** |
* Allocates n more default T values, and returns the address of the start |
* of that new range. Note: this address is only valid until the next API |
* call made on the array that might add or remove elements. |
@@ -261,6 +271,34 @@ |
} |
/** |
+ * Version of above that uses a copy constructor to initialize all n items |
+ * to the same T. |
+ */ |
+ T* push_back_n(int n, const T& t) { |
+ SkASSERT(n >= 0); |
+ checkRealloc(n); |
+ for (int i = 0; i < n; ++i) { |
+ new (fItemArray + fCount + i) T(t); |
+ } |
+ fCount += n; |
+ return fItemArray + fCount - n; |
+ } |
+ |
+ /** |
+ * Version of above that uses a copy constructor to initialize the n items |
+ * to separate T values. |
+ */ |
+ T* push_back_n(int n, const T t[]) { |
+ SkASSERT(n >= 0); |
+ checkRealloc(n); |
+ for (int i = 0; i < n; ++i) { |
+ new (fItemArray + fCount + i) T(t[i]); |
+ } |
+ fCount += n; |
+ return fItemArray + fCount - n; |
+ } |
+ |
+ /** |
* Removes the last element. Not safe to call when count() == 0. |
*/ |
void pop_back() { |