Couchbase Lite C
Couchbase Lite C API
FLMutable.h
Go to the documentation of this file.
1//
2// FLMutable.h
3//
4// Copyright 2016-Present Couchbase, Inc.
5//
6// Use of this software is governed by the Business Source License included
7// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
8// in that file, in accordance with the Business Source License, use of this
9// software will be governed by the Apache License, Version 2.0, included in
10// the file licenses/APL2.txt.
11//
12
13#pragma once
14#ifndef _FLMUTABLE_H
15#define _FLMUTABLE_H
16
17#include "FLValue.h"
18
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25 // This is the C API! For the C++ API, see Fleece.hh.
26
27
33 typedef enum {
39
40
41 //====== MUTABLE ARRAY
42
43
60
64
68 }
72 }
73
76
79
82 bool changed) FLAPI;
83
89 uint32_t firstIndex,
90 uint32_t count) FLAPI;
91
97 uint32_t firstIndex,
98 uint32_t count) FLAPI;
99
104 uint32_t size) FLAPI;
105
112 uint32_t index) FLAPI;
113
120 uint32_t index) FLAPI;
121
122
124 static inline void FLMutableArray_SetNull(FLMutableArray, uint32_t index);
126 static inline void FLMutableArray_SetBool(FLMutableArray, uint32_t index, bool);
128 static inline void FLMutableArray_SetInt(FLMutableArray, uint32_t index, int64_t);
132 static inline void FLMutableArray_SetUInt(FLMutableArray, uint32_t index, uint64_t);
134 static inline void FLMutableArray_SetFloat(FLMutableArray, uint32_t index, float);
136 static inline void FLMutableArray_SetDouble(FLMutableArray, uint32_t index, double);
138 static inline void FLMutableArray_SetString(FLMutableArray, uint32_t index, FLString);
140 static inline void FLMutableArray_SetData(FLMutableArray, uint32_t index, FLSlice);
142 static inline void FLMutableArray_SetValue(FLMutableArray, uint32_t index, FLValue);
144 static inline void FLMutableArray_SetArray(FLMutableArray, uint32_t index, FLArray);
146 static inline void FLMutableArray_SetDict(FLMutableArray, uint32_t index, FLDict);
147
149 static inline void FLMutableArray_AppendNull(FLMutableArray);
151 static inline void FLMutableArray_AppendBool(FLMutableArray, bool);
153 static inline void FLMutableArray_AppendInt(FLMutableArray, int64_t);
157 static inline void FLMutableArray_AppendUInt(FLMutableArray, uint64_t);
159 static inline void FLMutableArray_AppendFloat(FLMutableArray, float);
161 static inline void FLMutableArray_AppendDouble(FLMutableArray, double);
172
176 //====== MUTABLE DICT
177
178
193
197
201 }
202
206 }
207
210
213
216
219
222
229
236
237
239 static inline void FLMutableDict_SetNull(FLMutableDict, FLString key);
241 static inline void FLMutableDict_SetBool(FLMutableDict, FLString key, bool);
243 static inline void FLMutableDict_SetInt(FLMutableDict, FLString key, int64_t);
247 static inline void FLMutableDict_SetUInt(FLMutableDict, FLString key, uint64_t);
249 static inline void FLMutableDict_SetFloat(FLMutableDict, FLString key, float);
251 static inline void FLMutableDict_SetDouble(FLMutableDict, FLString key, double);
253 static inline void FLMutableDict_SetString(FLMutableDict, FLString key, FLString);
255 static inline void FLMutableDict_SetData(FLMutableDict, FLString key, FLSlice);
257 static inline void FLMutableDict_SetValue(FLMutableDict, FLString key, FLValue);
259 static inline void FLMutableDict_SetArray(FLMutableDict, FLString key, FLArray);
261 static inline void FLMutableDict_SetDict(FLMutableDict, FLString key, FLDict);
262
266 //====== NEWSTRING, NEWDATA
267
268
276
281
285 //====== VALUE SLOTS
286
287
308
315
322
323
333
334 static inline void FLSlot_SetArray(FLSlot slot, FLArray array) {
335 FLSlot_SetValue(slot, (FLValue)array);
336 }
337
338 static inline void FLSlot_SetDict(FLSlot slot, FLDict dict) {
339 FLSlot_SetValue(slot, (FLValue)dict);
340 }
341
342
343 // implementations of the inline methods declared earlier:
344
345 static inline void FLMutableArray_SetNull(FLMutableArray a, uint32_t index) {
347 }
348 static inline void FLMutableArray_SetBool(FLMutableArray a, uint32_t index, bool val) {
349 FLSlot_SetBool(FLMutableArray_Set(a, index), val);
350 }
351 static inline void FLMutableArray_SetInt(FLMutableArray a, uint32_t index, int64_t val) {
352 FLSlot_SetInt(FLMutableArray_Set(a, index), val);
353 }
354 static inline void FLMutableArray_SetUInt(FLMutableArray a, uint32_t index, uint64_t val) {
355 FLSlot_SetUInt(FLMutableArray_Set(a, index), val);
356 }
357 static inline void FLMutableArray_SetFloat(FLMutableArray a, uint32_t index, float val) {
358 FLSlot_SetFloat(FLMutableArray_Set(a, index), val);
359 }
360 static inline void FLMutableArray_SetDouble(FLMutableArray a, uint32_t index, double val) {
361 FLSlot_SetDouble(FLMutableArray_Set(a, index), val);
362 }
363 static inline void FLMutableArray_SetString(FLMutableArray a, uint32_t index, FLString val) {
364 FLSlot_SetString(FLMutableArray_Set(a, index), val);
365 }
366 static inline void FLMutableArray_SetData(FLMutableArray a, uint32_t index, FLSlice val) {
367 FLSlot_SetData(FLMutableArray_Set(a, index), val);
368 }
369 static inline void FLMutableArray_SetValue(FLMutableArray a, uint32_t index, FLValue val) {
370 FLSlot_SetValue(FLMutableArray_Set(a, index), val);
371 }
372 static inline void FLMutableArray_SetArray(FLMutableArray a, uint32_t index, FLArray val) {
374 }
375 static inline void FLMutableArray_SetDict(FLMutableArray a, uint32_t index, FLDict val) {
377 }
378
381 }
382 static inline void FLMutableArray_AppendBool(FLMutableArray a, bool val) {
384 }
385 static inline void FLMutableArray_AppendInt(FLMutableArray a, int64_t val) {
387 }
388 static inline void FLMutableArray_AppendUInt(FLMutableArray a, uint64_t val) {
390 }
391 static inline void FLMutableArray_AppendFloat(FLMutableArray a, float val) {
393 }
394 static inline void FLMutableArray_AppendDouble(FLMutableArray a, double val) {
396 }
399 }
402 }
405 }
408 }
411 }
412
413 static inline void FLMutableDict_SetNull(FLMutableDict d, FLString key) {
415 }
416 static inline void FLMutableDict_SetBool(FLMutableDict d, FLString key, bool val) {
417 FLSlot_SetBool(FLMutableDict_Set(d, key), val);
418 }
419 static inline void FLMutableDict_SetInt(FLMutableDict d, FLString key, int64_t val) {
420 FLSlot_SetInt(FLMutableDict_Set(d, key), val);
421 }
422 static inline void FLMutableDict_SetUInt(FLMutableDict d, FLString key, uint64_t val) {
423 FLSlot_SetUInt(FLMutableDict_Set(d, key), val);
424 }
425 static inline void FLMutableDict_SetFloat(FLMutableDict d, FLString key, float val) {
427 }
428 static inline void FLMutableDict_SetDouble(FLMutableDict d, FLString key, double val) {
430 }
431 static inline void FLMutableDict_SetString(FLMutableDict d, FLString key, FLString val) {
433 }
434 static inline void FLMutableDict_SetData(FLMutableDict d, FLString key, FLSlice val) {
435 FLSlot_SetData(FLMutableDict_Set(d, key), val);
436 }
437 static inline void FLMutableDict_SetValue(FLMutableDict d, FLString key, FLValue val) {
439 }
440 static inline void FLMutableDict_SetArray(FLMutableDict d, FLString key, FLArray val) {
442 }
443 static inline void FLMutableDict_SetDict(FLMutableDict d, FLString key, FLDict val) {
445 }
446
447
451#ifdef __cplusplus
452}
453#endif
454
456
457#endif // _FLMUTABLE_H
#define FL_NULLABLE
Definition: CompilerSupport.h:74
#define FLEECE_PUBLIC
Definition: CompilerSupport.h:241
#define FL_ASSUME_NONNULL_BEGIN
Definition: CompilerSupport.h:72
#define FL_ASSUME_NONNULL_END
Definition: CompilerSupport.h:73
#define FLAPI
Definition: CompilerSupport.h:247
#define MUST_USE_RESULT
Definition: CompilerSupport.h:53
FLEECE_PUBLIC void FLValue_Release(FLValue FL_NULLABLE)
Decrements the ref-count of a mutable value, or of an immutable value's FLDoc.
FLEECE_PUBLIC FLValue FL_NULLABLE FLValue_Retain(FLValue FL_NULLABLE)
Increments the ref-count of a mutable value, or of an immutable value's FLDoc.
static void FLMutableArray_SetInt(FLMutableArray, uint32_t index, int64_t)
Stores an integer into an array.
Definition: FLMutable.h:351
FLEECE_PUBLIC void FLMutableDict_Remove(FLMutableDict FL_NULLABLE, FLString key)
Removes the value for a key.
FLCopyFlags
Option flags for making mutable copies of values.
Definition: FLMutable.h:33
FLEECE_PUBLIC FLMutableArray FL_NULLABLE FLMutableDict_GetMutableArray(FLMutableDict FL_NULLABLE, FLString key)
Convenience function for getting an array-valued property in mutable form.
FLEECE_PUBLIC FLValue FL_NULLABLE FLValue_NewString(FLString)
Allocates a string value on the heap.
static void FLMutableDict_SetDict(FLMutableDict, FLString key, FLDict)
Stores a Fleece dictionary into a mutable dictionary.
Definition: FLMutable.h:443
static void FLMutableArray_AppendDict(FLMutableArray, FLDict)
Appends a Fleece dictionary to an array.
Definition: FLMutable.h:409
static void FLMutableDict_SetNull(FLMutableDict, FLString key)
Stores a JSON null value into a mutable dictionary.
Definition: FLMutable.h:413
static void FLMutableArray_SetArray(FLMutableArray, uint32_t index, FLArray)
Stores a Fleece array into an array.
Definition: FLMutable.h:372
FLEECE_PUBLIC void FLMutableDict_RemoveAll(FLMutableDict FL_NULLABLE)
Removes all keys and values.
FLEECE_PUBLIC FLMutableArray FL_NULLABLE FLMutableArray_GetMutableArray(FLMutableArray FL_NULLABLE, uint32_t index)
Convenience function for getting an array-valued property in mutable form.
static void FLMutableArray_AppendDouble(FLMutableArray, double)
Appends a 64-bit floating point number to an array.
Definition: FLMutable.h:394
static void FLMutableArray_SetUInt(FLMutableArray, uint32_t index, uint64_t)
Stores an unsigned integer into an array.
Definition: FLMutable.h:354
FLEECE_PUBLIC FLMutableDict FL_NULLABLE FLDict_MutableCopy(FLDict FL_NULLABLE source, FLCopyFlags)
Creates a new mutable Dict that's a copy of the source Dict.
static void FLMutableArray_AppendUInt(FLMutableArray, uint64_t)
Appends an unsigned integer to an array.
Definition: FLMutable.h:388
FLEECE_PUBLIC FLMutableDict FL_NULLABLE FLMutableDict_GetMutableDict(FLMutableDict FL_NULLABLE, FLString key)
Convenience function for getting a dict-valued property in mutable form.
FLEECE_PUBLIC FLDict FL_NULLABLE FLMutableDict_GetSource(FLMutableDict FL_NULLABLE)
If the Dict was created by FLDict_MutableCopy, returns the original source Dict.
FLEECE_PUBLIC void FLMutableArray_Insert(FLMutableArray FL_NULLABLE array, uint32_t firstIndex, uint32_t count)
Inserts a contiguous range of JSON null values into the array.
static void FLMutableArray_SetFloat(FLMutableArray, uint32_t index, float)
Stores a 32-bit floating-point number into an array.
Definition: FLMutable.h:357
FLEECE_PUBLIC void FLMutableArray_Resize(FLMutableArray FL_NULLABLE array, uint32_t size)
Changes the size of an array.
FLEECE_PUBLIC FLMutableArray FL_NULLABLE FLMutableArray_New(void)
Creates a new empty mutable Array.
FLEECE_PUBLIC FLMutableDict FL_NULLABLE FLMutableDict_New(void)
Creates a new empty mutable Dict.
static void FLMutableArray_SetDict(FLMutableArray, uint32_t index, FLDict)
Stores a Fleece dictionary into an array.
Definition: FLMutable.h:375
static void FLMutableArray_AppendInt(FLMutableArray, int64_t)
Appends an integer to an array.
Definition: FLMutable.h:385
static void FLMutableDict_SetData(FLMutableDict, FLString key, FLSlice)
Stores a binary data blob into a mutable dictionary.
Definition: FLMutable.h:434
static void FLMutableArray_SetString(FLMutableArray, uint32_t index, FLString)
Stores a UTF-8-encoded string into an array.
Definition: FLMutable.h:363
static void FLMutableArray_AppendBool(FLMutableArray, bool)
Appends a boolean value to an array.
Definition: FLMutable.h:382
static void FLMutableArray_AppendString(FLMutableArray, FLString)
Appends a UTF-8-encoded string to an array.
Definition: FLMutable.h:397
FLEECE_PUBLIC void FLMutableArray_SetChanged(FLMutableArray FL_NULLABLE, bool changed)
Sets or clears the mutable Array's "changed" flag.
FLEECE_PUBLIC bool FLMutableDict_IsChanged(FLMutableDict FL_NULLABLE)
Returns true if the Dict has been changed from the source it was copied from.
static void FLMutableDict_Release(FLMutableDict FL_NULLABLE d)
Decrements the refcount of (and possibly frees) a mutable Dict.
Definition: FLMutable.h:204
FLEECE_PUBLIC FLArray FL_NULLABLE FLMutableArray_GetSource(FLMutableArray FL_NULLABLE)
If the Array was created by FLArray_MutableCopy, returns the original source Array.
FLEECE_PUBLIC FLValue FL_NULLABLE FLValue_NewData(FLSlice)
Allocates a data/blob value on the heap.
static void FLMutableArray_SetDouble(FLMutableArray, uint32_t index, double)
Stores a 64-bit floating point number into an array.
Definition: FLMutable.h:360
static FLMutableDict FL_NULLABLE FLMutableDict_Retain(FLMutableDict FL_NULLABLE d)
Increments the ref-count of a mutable Dict.
Definition: FLMutable.h:199
static void FLMutableDict_SetFloat(FLMutableDict, FLString key, float)
Stores a 32-bit floating-point number into a mutable dictionary.
Definition: FLMutable.h:425
FLEECE_PUBLIC bool FLMutableArray_IsChanged(FLMutableArray FL_NULLABLE)
Returns true if the Array has been changed from the source it was copied from.
static void FLMutableDict_SetInt(FLMutableDict, FLString key, int64_t)
Stores an integer into a mutable dictionary.
Definition: FLMutable.h:419
static void FLMutableDict_SetValue(FLMutableDict, FLString key, FLValue)
Stores a Fleece value into a mutable dictionary.
Definition: FLMutable.h:437
static void FLMutableArray_AppendValue(FLMutableArray, FLValue)
Appends a Fleece value to an array.
Definition: FLMutable.h:403
static void FLMutableDict_SetDouble(FLMutableDict, FLString key, double)
Stores a 64-bit floating point number into a mutable dictionary.
Definition: FLMutable.h:428
FLEECE_PUBLIC FLMutableArray FL_NULLABLE FLArray_MutableCopy(FLArray FL_NULLABLE, FLCopyFlags)
Creates a new mutable Array that's a copy of the source Array.
static void FLMutableArray_SetData(FLMutableArray, uint32_t index, FLSlice)
Stores a binary data blob into an array.
Definition: FLMutable.h:366
static void FLMutableArray_Release(FLMutableArray FL_NULLABLE d)
Decrements the refcount of (and possibly frees) a mutable Array.
Definition: FLMutable.h:70
static void FLMutableArray_SetBool(FLMutableArray, uint32_t index, bool)
Stores a boolean value into an array.
Definition: FLMutable.h:348
FLEECE_PUBLIC FLMutableDict FL_NULLABLE FLMutableArray_GetMutableDict(FLMutableArray FL_NULLABLE, uint32_t index)
Convenience function for getting an array-valued property in mutable form.
static void FLMutableArray_AppendNull(FLMutableArray)
Appends a JSON null value to an array.
Definition: FLMutable.h:379
static FLMutableArray FL_NULLABLE FLMutableArray_Retain(FLMutableArray FL_NULLABLE d)
Increments the ref-count of a mutable Array.
Definition: FLMutable.h:66
static void FLMutableDict_SetBool(FLMutableDict, FLString key, bool)
Stores a boolean value into a mutable dictionary.
Definition: FLMutable.h:416
static void FLMutableDict_SetArray(FLMutableDict, FLString key, FLArray)
Stores a Fleece array into a mutable dictionary.
Definition: FLMutable.h:440
static void FLMutableDict_SetString(FLMutableDict, FLString key, FLString)
Stores a UTF-8-encoded string into a mutable dictionary.
Definition: FLMutable.h:431
static void FLMutableArray_SetNull(FLMutableArray, uint32_t index)
Stores a JSON null value into an array.
Definition: FLMutable.h:345
static void FLMutableArray_AppendData(FLMutableArray, FLSlice)
Appends a binary data blob to an array.
Definition: FLMutable.h:400
FLEECE_PUBLIC void FLMutableArray_Remove(FLMutableArray FL_NULLABLE array, uint32_t firstIndex, uint32_t count)
Removes contiguous items from the array.
static void FLMutableArray_AppendFloat(FLMutableArray, float)
Appends a 32-bit floating-point number to an array.
Definition: FLMutable.h:391
FLEECE_PUBLIC void FLMutableDict_SetChanged(FLMutableDict FL_NULLABLE, bool)
Sets or clears the mutable Dict's "changed" flag.
static void FLMutableArray_SetValue(FLMutableArray, uint32_t index, FLValue)
Stores a Fleece value into an array.
Definition: FLMutable.h:369
static void FLMutableDict_SetUInt(FLMutableDict, FLString key, uint64_t)
Stores an unsigned integer into a mutable dictionary.
Definition: FLMutable.h:422
static void FLMutableArray_AppendArray(FLMutableArray, FLArray)
Appends a Fleece array to an array.
Definition: FLMutable.h:406
@ kFLDeepCopy
Deep copy of mutable values.
Definition: FLMutable.h:35
@ kFLCopyImmutables
Makes mutable copies of immutables instead of just refs.
Definition: FLMutable.h:36
@ kFLDefaultCopy
Shallow copy. References immutables instead of copying.
Definition: FLMutable.h:34
@ kFLDeepCopyImmutables
Both deep-copy and copy-immutables.
Definition: FLMutable.h:37
MUST_USE_RESULT FLEECE_PUBLIC FLSlot FLMutableArray_Set(FLMutableArray, uint32_t index)
Returns an FLSlot that refers to the given index of the given array.
FLEECE_PUBLIC void FLSlot_SetString(FLSlot, FLString)
Stores a UTF-8 string into a slot.
MUST_USE_RESULT FLEECE_PUBLIC FLSlot FLMutableDict_Set(FLMutableDict, FLString key)
Returns an FLSlot that refers to the given key/value pair of the given dictionary.
FLEECE_PUBLIC void FLSlot_SetNull(FLSlot)
Stores a JSON null into a slot.
FLEECE_PUBLIC void FLSlot_SetBool(FLSlot, bool)
Stores a boolean into a slot.
FLEECE_PUBLIC void FLSlot_SetUInt(FLSlot, uint64_t)
Stores an unsigned int into a slot.
FLEECE_PUBLIC void FLSlot_SetFloat(FLSlot, float)
Stores a float into a slot.
static void FLSlot_SetArray(FLSlot slot, FLArray array)
Definition: FLMutable.h:334
static void FLSlot_SetDict(FLSlot slot, FLDict dict)
Definition: FLMutable.h:338
FLEECE_PUBLIC void FLSlot_SetDouble(FLSlot, double)
Stores a double into a slot.
FLEECE_PUBLIC void FLSlot_SetValue(FLSlot, FLValue)
Stores an FLValue into a slot.
MUST_USE_RESULT FLEECE_PUBLIC FLSlot FLMutableArray_Append(FLMutableArray)
Appends a null value to the array and returns an FLSlot that refers to that position.
FLEECE_PUBLIC void FLSlot_SetInt(FLSlot, int64_t)
Stores an integer into a slot.
FLEECE_PUBLIC void FLSlot_SetData(FLSlot, FLSlice)
Stores a data blob into a slot.
struct _FLDict * FLMutableDict
A reference to a mutable dictionary.
Definition: FLBase.h:40
const struct _FLDict * FLDict
A reference to a dictionary (map) value.
Definition: FLBase.h:37
struct _FLSlot * FLSlot
A reference to a mutable array/dict item.
Definition: FLBase.h:38
struct _FLArray * FLMutableArray
A reference to a mutable array.
Definition: FLBase.h:39
const struct _FLArray * FLArray
A reference to an array value.
Definition: FLBase.h:36
const struct _FLValue * FLValue
A reference to a value of any type.
Definition: FLBase.h:35
A simple reference to a block of memory.
Definition: FLSlice.h:45