|
C Client-Side SDK
LaunchDarkly SDK
|
|
3 #include <unordered_map>
14 namespace launchdarkly {
21 Array(std::initializer_list<Value>);
26 friend bool operator== (
const Array&,
const Array&) =
delete;
32 Array& add(
const char *);
33 Array& add(
const std::string&);
46 Object(std::initializer_list<std::pair<const char*, Value>>);
51 friend bool operator== (
const Object&,
const Object&) =
delete;
53 void set(
const char* key,
const Value& value);
54 void set(
const char *key,
Value&& value);
56 void set(
const char *key,
bool value);
57 void set(
const char *key,
double value);
58 void set(
const char *key,
const char *value);
59 void set(
const char *key,
const std::string& value);
119 :ptr{
LDValue_Bool(b ? LDBooleanTrue : LDBooleanFalse)} {}
140 explicit Value(
const std::string& b)
148 :ptr{ array.build().
release() } {}
155 :ptr{ obj.build().
release() } {}
169 :ptr {other.release()} {}
176 return *
this =
Value(other);
186 std::swap(ptr, other.ptr);
198 friend bool operator== (
const Value& c1,
const Value& c2) {
202 friend bool operator!= (
const Value& c1,
const Value& c2) {
236 std::string r = serialized;
247 std::string r = serialized;
263 return Value(parsed);
298 std::vector<Value> values;
311 std::unordered_map<std::string, Value>
313 std::unordered_map<std::string, Value> map;
347 struct LDValue* raw = ptr;
364 Array::Array(std::initializer_list<Value> init) :ptr{
LDArray_New()} {
365 for (
auto copy : init) {
370 Array& Array::add(
const Value& v) {
376 Array& Array::add(Value&& v) {
381 Array& Array::add(
bool b) { add(Value(b));
return *
this;}
382 Array& Array::add(
double b) { add(Value(b));
return *
this; }
383 Array& Array::add(
const char *b) { add(Value(b));
return *
this; }
384 Array& Array::add(
const std::string& b) { add(Value(b));
return *
this; }
386 Value Array::build()
const {
394 Object::Object(std::initializer_list<std::pair<const char*, Value>> init)
396 for (
auto kv : init) {
406 void Object::set(
const char* key,
const Value& value) {
411 void Object::set(
const char *key, Value&& value) {
415 void Object::set(
const char *key,
bool value) { set(key, Value(value)); }
416 void Object::set(
const char *key,
double value) { set(key, Value(value)); }
417 void Object::set(
const char *key,
const char *val) { set(key, Value(val)); }
418 void Object::set(
const char *key,
const std::string& val) { set(key, Value(val)); }
420 Value Object::build()
const {
@ LDValueType_Object
Definition: ldvalue.h:42
struct LDObject * LDObject_New(void)
@ LDValueType_Number
Definition: ldvalue.h:30
void LDObject_Free(struct LDObject *obj)
struct LDArray * LDArray_New(void)
@ LDValueType_Unrecognized
Definition: ldvalue.h:18
const char * LDValue_GetString(struct LDValue *value)
Value & operator=(Value &&other) noexcept
Definition: value.hpp:183
bool is_null() const
Definition: value.hpp:335
~Value()
Definition: value.hpp:193
void LDArray_Free(struct LDArray *array)
Type
Definition: value.hpp:68
bool get_bool() const
Definition: value.hpp:270
struct LDValue * LDValue_Number(double number)
struct LDValue * LDValue_OwnedString(const char *string)
static Value parse_json(const char *json)
Definition: value.hpp:258
unsigned int LDValue_Count(struct LDValue *value)
@ LDValueType_Null
Definition: ldvalue.h:22
Value(Value &&other) noexcept
Definition: value.hpp:168
std::string get_string() const
Definition: value.hpp:278
void LDObject_AddConstantKey(struct LDObject *obj, const char *key, struct LDValue *value)
Value(const Object &obj)
Definition: value.hpp:154
struct LDValue * LDValue_ParseJSON(const char *json)
struct LDIter * LDValue_GetIter(struct LDValue *value)
struct LDValue * LDValue_Clone(struct LDValue *source)
struct LDValue * LDObject_Build(struct LDObject *obj)
struct LDValue * release()
Definition: value.hpp:346
Value & operator=(const Value &other)
Definition: value.hpp:175
Value(bool b)
Definition: value.hpp:118
struct LDValue * LDValue_Bool(LDBoolean boolean)
Value(const Array &array)
Definition: value.hpp:147
@ LDArray
JSON integer indexed array.
Definition: json.h:29
char * LDValue_SerializeJSON(struct LDValue *value)
void LDFree(void *const buffer)
Equivalent to free
LDBoolean LDValue_Equal(struct LDValue *a, struct LDValue *b)
std::string serialize_json()
Definition: value.hpp:234
Value(const std::string &b)
Definition: value.hpp:140
const char * LDIter_Key(struct LDIter *iterator)
struct LDIter * LDIter_Next(struct LDIter *iterator)
double get_number() const
Definition: value.hpp:286
Value()
Definition: value.hpp:111
size_t count() const
Definition: value.hpp:327
std::vector< Value > into_vector() const
Definition: value.hpp:297
struct LDValue * LDValue_Null(void)
struct LDValue * LDValue_ConstantString(const char *string)
void LDArray_Add(struct LDArray *array, struct LDValue *value)
@ LDValueType_String
Definition: ldvalue.h:34
Value(const Value &other)
Definition: value.hpp:161
LDBoolean LDValue_GetBool(struct LDValue *value)
char * LDValue_SerializeFormattedJSON(struct LDValue *value)
@ LDValueType_Bool
Definition: ldvalue.h:26
struct LDValue * LDArray_Build(struct LDArray *array)
LDValues represent immutable JSON values.
Value(double b)
Definition: value.hpp:125
struct LDValue * LDIter_Val(struct LDIter *iterator)
Value(struct LDValue *ptr)
Definition: value.hpp:104
void LDValue_Free(struct LDValue *value)
@ LDObject
JSON string indexed map.
Definition: json.h:27
@ LDValueType_Array
Definition: ldvalue.h:38
std::string serialize_formatted_json()
Definition: value.hpp:245
std::unordered_map< std::string, Value > into_unordered_map() const
Definition: value.hpp:312
enum LDValueType LDValue_Type(struct LDValue *value)
double LDValue_GetNumber(struct LDValue *value)
Public API. Operations for managing memory.
Value(const char *b)
Definition: value.hpp:133
Type type() const
Definition: value.hpp:211