| 24 | namespace fleece { namespace impl { namespace internal { |
| 25 | |
| 26 | class HeapArray : public HeapCollection { |
| 27 | public: |
| 28 | HeapArray() |
| 29 | :HeapCollection(kArrayTag) |
| 30 | { } |
| 31 | |
| 32 | HeapArray(uint32_t initialCount) |
| 33 | :HeapCollection(kArrayTag) |
| 34 | ,_items(initialCount) |
| 35 | { } |
| 36 | |
| 37 | HeapArray(const Array*); |
| 38 | |
| 39 | static MutableArray* asMutableArray(HeapArray *a) {return (MutableArray*)asValue(a);} |
| 40 | MutableArray* asMutableArray() const {return (MutableArray*)asValue();} |
| 41 | |
| 42 | uint32_t count() const {return (uint32_t)_items.size();} |
| 43 | bool empty() const {return _items.empty();} |
| 44 | |
| 45 | const Array* source() const {return _source;} |
| 46 | |
| 47 | const Value* get(uint32_t index); |
| 48 | |
| 49 | ValueSlot& setting(uint32_t index); |
| 50 | ValueSlot& appending(); |
| 51 | ValueSlot& inserting(uint32_t index) {insert(index, 1); return setting(index);} |
| 52 | |
| 53 | |
| 54 | template <typename T> |
| 55 | void set(uint32_t index, T t) {setting(index).set(t);} |
| 56 | |
| 57 | // Warning: Changing the size of a MutableArray invalidates pointers to items that are |
| 58 | // small scalar values, and also invalidates iterators. |
| 59 | |
| 60 | /** Appends a new Value. */ |
| 61 | template <typename T> |
| 62 | void append(const T &t) {appending().set(t);} |
| 63 | |
| 64 | |
| 65 | void resize(uint32_t newSize); ///< Appends nulls, or removes items from end |
| 66 | void insert(uint32_t where, uint32_t n); ///< Inserts `n` nulls at index `where` |
| 67 | void remove(uint32_t where, uint32_t n); ///< Removes items starting at index `where` |
| 68 | |
| 69 | /** Promotes an Array item to a MutableArray (in place) and returns it. |
| 70 | Or if the item is already a MutableArray, just returns it. Else returns null. */ |
| 71 | MutableArray* getMutableArray(uint32_t i); |
| 72 | |
| 73 | /** Promotes a Dict item to a MutableDict (in place) and returns it. |
| 74 | Or if the item is already a MutableDict, just returns it. Else returns null. */ |
| 75 | MutableDict* getMutableDict(uint32_t i); |
| 76 | |
| 77 | void disconnectFromSource(); |
| 78 | void copyChildren(CopyFlags flags); |
| 79 | |
| 80 | class iterator { |
| 81 | public: |
| 82 | iterator(const HeapArray* NONNULL) noexcept; |
| 83 | iterator(const MutableArray* NONNULL) noexcept; |