MCPcopy Create free account
hub / github.com/couchbase/fleece / MutableArray

Class MutableArray

API/fleece/Mutable.hh:77–147  ·  view source on GitHub ↗

A mutable form of Array. Its storage lives in the heap, not in the (immutable) Fleece document. It can be used to make a changed form of a document, which can then be encoded to a new Fleece document. */

Source from the content-addressed store, hash-verified

75 document. It can be used to make a changed form of a document, which can then be
76 encoded to a new Fleece document. */
77 class MutableArray : public Array {
78 public:
79 /** Creates a new, empty mutable array. */
80 static MutableArray newArray() {return MutableArray(FLMutableArray_New(), false);}
81
82 MutableArray() :Array() { }
83 MutableArray(FLMutableArray a) :Array((FLArray)FLMutableArray_Retain(a)) { }
84 MutableArray(const MutableArray &a) :Array((FLArray)FLMutableArray_Retain(a)) { }
85 MutableArray(MutableArray &&a) noexcept :Array((FLArray)a) {a._val = nullptr;}
86 ~MutableArray() {FLMutableArray_Release(*this);}
87
88 operator FLMutableArray () const {return (FLMutableArray)_val;}
89
90 MutableArray& operator= (const MutableArray &a) {
91 FLMutableArray_Retain(a);
92 FLMutableArray_Release(*this);
93 _val = a._val;
94 return *this;
95 }
96
97 MutableArray& operator= (MutableArray &&a) noexcept {
98 if (a._val != _val) {
99 FLMutableArray_Release(*this);
100 _val = a._val;
101 a._val = nullptr;
102 }
103 return *this;
104 }
105
106 /** The immutable Array this instance was constructed from (if any). */
107 Array source() const {return FLMutableArray_GetSource(*this);}
108
109 /** True if this array has been modified since it was created. */
110 bool isChanged() const {return FLMutableArray_IsChanged(*this);}
111
112 /** Removes a range of values from the array. */
113 void remove(uint32_t first, uint32_t n =1) {FLMutableArray_Remove(*this, first, n);}
114
115 /** Sets the array's size. If the array grows, new values begin as nulls. */
116 void resize(uint32_t size) {FLMutableArray_Resize(*this, size);}
117
118 Slot set(uint32_t i) {return Slot(FLMutableArray_Set(*this, i));}
119 void setNull(uint32_t i) {set(i).setNull();}
120
121 template <class T>
122 void set(uint32_t i, T v) {set(i) = v;}
123
124 Slot append() {return FLMutableArray_Append(*this);}
125 void appendNull() {append().setNull();}
126
127 template <class T>
128 void append(T v) {append() = v;}
129
130 void insertNulls(uint32_t i, uint32_t n) {FLMutableArray_Insert(*this, i, n);}
131
132 // This enables e.g. `array[10] = 17`
133 inline keyref<MutableArray,uint32_t> operator[] (int i) {
134 return keyref<MutableArray,uint32_t>(*this, i);

Callers 3

newArrayMethod · 0.70
mutableCopyMethod · 0.70
asMutableMethod · 0.70

Calls 2

FLMutableArray_RetainFunction · 0.85
FLMutableArray_ReleaseFunction · 0.85

Tested by

no test coverage detected