diff options
Diffstat (limited to 'core/vector.h')
-rw-r--r-- | core/vector.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/core/vector.h b/core/vector.h index 44add2c4d7..d3476679ff 100644 --- a/core/vector.h +++ b/core/vector.h @@ -34,7 +34,7 @@ /** * @class Vector * @author Juan Linietsky - * Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use PoolVector for large arrays. + * Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use Vector for large arrays. */ #include "core/cowdata.h" @@ -64,12 +64,13 @@ private: public: bool push_back(T p_elem); + _FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias void remove(int p_index) { _cowdata.remove(p_index); } void erase(const T &p_val) { int idx = find(p_val); if (idx >= 0) remove(idx); - }; + } void invert(); _FORCE_INLINE_ T *ptrw() { return _cowdata.ptrw(); } @@ -123,6 +124,30 @@ public: return *this; } + Vector<T> subarray(int p_from, int p_to) const { + + if (p_from < 0) { + p_from = size() + p_from; + } + if (p_to < 0) { + p_to = size() + p_to; + } + + ERR_FAIL_INDEX_V(p_from, size(), Vector<T>()); + ERR_FAIL_INDEX_V(p_to, size(), Vector<T>()); + + Vector<T> slice; + int span = 1 + p_to - p_from; + slice.resize(span); + const T *r = ptr(); + T *w = slice.ptrw(); + for (int i = 0; i < span; ++i) { + w[i] = r[p_from + i]; + } + + return slice; + } + _FORCE_INLINE_ ~Vector() {} }; |