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

Class MutableDict

API/fleece/Mutable.hh:153–211  ·  view source on GitHub ↗

A mutable form of Dict. 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

151 document. It can be used to make a changed form of a document, which can then be
152 encoded to a new Fleece document. */
153 class MutableDict : public Dict {
154 public:
155 static MutableDict newDict() {return MutableDict(FLMutableDict_New(), false);}
156
157 MutableDict() :Dict() { }
158 MutableDict(FLMutableDict d) :Dict((FLDict)d) {FLMutableDict_Retain(*this);}
159 MutableDict(const MutableDict &d) :Dict((FLDict)d) {FLMutableDict_Retain(*this);}
160 MutableDict(MutableDict &&d) noexcept :Dict((FLDict)d) {d._val = nullptr;}
161 ~MutableDict() {FLMutableDict_Release(*this);}
162
163 operator FLMutableDict () const {return (FLMutableDict)_val;}
164
165 MutableDict& operator= (const MutableDict &d) {
166 FLMutableDict_Retain(d);
167 FLMutableDict_Release(*this);
168 _val = d._val;
169 return *this;
170 }
171
172 MutableDict& operator= (MutableDict &&d) noexcept {
173 if (d._val != _val) {
174 FLMutableDict_Release(*this);
175 _val = d._val;
176 d._val = nullptr;
177 }
178 return *this;
179 }
180
181 Dict source() const {return FLMutableDict_GetSource(*this);}
182 bool isChanged() const {return FLMutableDict_IsChanged(*this);}
183
184 void remove(slice key) {FLMutableDict_Remove(*this, key);}
185
186 Slot set(slice key) {return FLMutableDict_Set(*this, key);}
187 void setNull(slice key) {set(key) = nullValue;}
188
189 template <class T>
190 void set(slice key, T v) {set(key) = v;}
191
192
193 // This enables e.g. `dict["key"_sl] = 17`
194 inline keyref<MutableDict,slice> operator[] (slice key)
195 {return keyref<MutableDict,slice>(*this, key);}
196 inline keyref<MutableDict,slice> operator[] (const char *key)
197 {return keyref<MutableDict,slice>(*this, slice(key));}
198 inline keyref<MutableDict,Key&> operator[] (Key &key)
199 {return keyref<MutableDict,Key&>(*this, key);}
200
201 inline Value operator[] (slice key) const {return Dict::get(key);}
202 inline Value operator[] (const char *key) const {return Dict::get(key);}
203
204 inline MutableArray getMutableArray(slice key);
205 inline MutableDict getMutableDict(slice key);
206
207 private:
208 MutableDict(FLMutableDict d, bool) :Dict((FLDict)d) {}
209 friend class RetainedValue;
210 friend class Dict;

Callers 3

newDictMethod · 0.70
mutableCopyMethod · 0.70
asMutableMethod · 0.70

Calls 2

FLMutableDict_RetainFunction · 0.85
FLMutableDict_ReleaseFunction · 0.85

Tested by

no test coverage detected