* An array of Value items. * * @ingroup base */
| 23 | * @ingroup base |
| 24 | */ |
| 25 | class Array final : public Object |
| 26 | { |
| 27 | public: |
| 28 | DECLARE_OBJECT(Array); |
| 29 | |
| 30 | /** |
| 31 | * An iterator that can be used to iterate over array elements. |
| 32 | */ |
| 33 | typedef std::vector<Value>::iterator Iterator; |
| 34 | |
| 35 | typedef std::vector<Value>::size_type SizeType; |
| 36 | |
| 37 | Array() = default; |
| 38 | Array(const ArrayData& other); |
| 39 | Array(ArrayData&& other); |
| 40 | Array(std::initializer_list<Value> init); |
| 41 | |
| 42 | Value Get(SizeType index) const; |
| 43 | void Set(SizeType index, const Value& value); |
| 44 | void Set(SizeType index, Value&& value); |
| 45 | void Add(Value value); |
| 46 | |
| 47 | Iterator Begin(); |
| 48 | Iterator End(); |
| 49 | |
| 50 | size_t GetLength() const; |
| 51 | bool Contains(const Value& value) const; |
| 52 | |
| 53 | void Insert(SizeType index, Value value); |
| 54 | void Remove(SizeType index); |
| 55 | void Remove(Iterator it); |
| 56 | |
| 57 | void Resize(SizeType newSize); |
| 58 | void Clear(); |
| 59 | |
| 60 | void Reserve(SizeType newSize); |
| 61 | |
| 62 | void CopyTo(const Array::Ptr& dest) const; |
| 63 | Array::Ptr ShallowClone() const; |
| 64 | |
| 65 | static Object::Ptr GetPrototype(); |
| 66 | |
| 67 | template<typename T> |
| 68 | static Array::Ptr FromVector(const std::vector<T>& v) |
| 69 | { |
| 70 | Array::Ptr result = new Array(); |
| 71 | ObjectLock olock(result); |
| 72 | std::copy(v.begin(), v.end(), std::back_inserter(result->m_Data)); |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | template<typename T> |
| 77 | std::set<T> ToSet() |
| 78 | { |
| 79 | ObjectLock olock(this); |
| 80 | return std::set<T>(Begin(), End()); |
| 81 | } |
| 82 |
nothing calls this directly
no outgoing calls
no test coverage detected