C Client-Side SDK
LaunchDarkly SDK
launchdarkly::Value Class Reference

Public Types

enum  Type { Type::Unrecognized, Type::Null, Type::Bool, Type::Number, Type::String, Type::Array, Type::Object }
 

Public Member Functions

 Value (struct LDValue *ptr)
 
 Value ()
 
 Value (bool b)
 
 Value (double b)
 
 Value (const char *b)
 
 Value (const std::string &b)
 
 Value (const Array &array)
 
 Value (const Object &obj)
 
 Value (const Value &other)
 
 Value (Value &&other) noexcept
 
Valueoperator= (const Value &other)
 
Valueoperator= (Value &&other) noexcept
 
 ~Value ()
 
Type type () const
 
std::string serialize_json ()
 
std::string serialize_formatted_json ()
 
bool get_bool () const
 
std::string get_string () const
 
double get_number () const
 
std::vector< Valueinto_vector () const
 
std::unordered_map< std::string, Valueinto_unordered_map () const
 
size_t count () const
 
bool is_null () const
 
struct LDValue * release ()
 

Static Public Member Functions

static Value parse_json (const char *json)
 

Friends

bool operator== (const Value &c1, const Value &c2)
 
bool operator!= (const Value &c1, const Value &c2)
 

Member Enumeration Documentation

◆ Type

Enumerator
Unrecognized 

The value's type is unrecognized.

Null 

The value is null.

Bool 

The value is a boolean.

Number 

The value is a number. JSON does not have separate types for integers and floats.

String 

The value is a string.

Array 

The value is an array.

Object 

The value is an object.

Constructor & Destructor Documentation

◆ Value() [1/10]

launchdarkly::Value::Value ( struct LDValue *  ptr)
inlineexplicit

Constructs a Value from a raw pointer. Ownership is transferred to the Value.

Parameters
ptrRaw pointer.

◆ Value() [2/10]

launchdarkly::Value::Value ( )
inlineexplicit

Constructs a null-type Value. Represents the JSON "null".

◆ Value() [3/10]

launchdarkly::Value::Value ( bool  b)
inlineexplicit

Constructs a Value from a boolean.

Parameters
bBoolean value.

◆ Value() [4/10]

launchdarkly::Value::Value ( double  b)
inlineexplicit

Constructs a Value from a double.

Parameters
bDouble value.

◆ Value() [5/10]

launchdarkly::Value::Value ( const char *  b)
inlineexplicit

Constructs a Value from a string literal.

Parameters
bString literal. The pointer must remain valid for the duration of the program.

◆ Value() [6/10]

launchdarkly::Value::Value ( const std::string &  b)
inlineexplicit

Constructs a Value from an std::string.

Parameters
bString object. The string is cloned.

◆ Value() [7/10]

launchdarkly::Value::Value ( const Array array)
inline

Implicit construction of a Value from an Array builder.

Parameters
arrayArray builder.

◆ Value() [8/10]

launchdarkly::Value::Value ( const Object obj)
inline

Implicit construction of a Value from an Object builder.

Parameters
objObject builder.

◆ Value() [9/10]

launchdarkly::Value::Value ( const Value other)
inline

Constructs a Value from another Value.

Parameters
otherThe Value to clone.

◆ Value() [10/10]

launchdarkly::Value::Value ( Value &&  other)
inlinenoexcept

Move constructs a Value from another Value.

Parameters
otherThe Value to consume.

◆ ~Value()

launchdarkly::Value::~Value ( )
inline

Destroys the Value and any child Values.

Member Function Documentation

◆ count()

size_t launchdarkly::Value::count ( ) const
inline

Count how many elements are in an array-type or object-type Value.

Returns
Element count, or 0 if not array or object-type.

◆ get_bool()

bool launchdarkly::Value::get_bool ( ) const
inline

Retrieve the boolean value.

Returns
Boolean value, or false if not a bool.

◆ get_number()

double launchdarkly::Value::get_number ( ) const
inline

Retrieve the number value.

Returns
Number value, or 0.0 if not a number.

◆ get_string()

std::string launchdarkly::Value::get_string ( ) const
inline

Retrieve the string value.

Returns
String value, or empty string if not a string.

◆ into_unordered_map()

std::unordered_map<std::string, Value> launchdarkly::Value::into_unordered_map ( ) const
inline

Construct an unordered map of key/Values from an object-type Value. The new keys/values are cloned from the Value, which may be an expensive operation.

Returns
Map of key/values if object-type, otherwise empty unordered map.

◆ into_vector()

std::vector<Value> launchdarkly::Value::into_vector ( ) const
inline

Construct a vector of individual Values from an array-type (or object-type) Value. The new values are cloned from the Value, which may be an expensive operation.

Returns
Vector of Values if array-type/object-type, or an empty vector.

◆ is_null()

bool launchdarkly::Value::is_null ( ) const
inline

Check if Value represents null.

Returns
True if null-type.

◆ operator=() [1/2]

Value& launchdarkly::Value::operator= ( const Value other)
inline

Copy assigns this Value from another Value.

Parameters
otherValue to copy.

◆ operator=() [2/2]

Value& launchdarkly::Value::operator= ( Value &&  other)
inlinenoexcept

Move assigns this Value from another Value.

Parameters
otherThe Value to move from.

◆ parse_json()

static Value launchdarkly::Value::parse_json ( const char *  json)
inlinestatic

Constructs a Value from a JSON string.

Parameters
jsonInput JSON string.
Returns
Constructed Value. The Value may be of type null if the JSON couldn't be parsed.

◆ release()

struct LDValue* launchdarkly::Value::release ( )
inline

Releases the managed LDValue pointer. Only necessary when interfacing with C code where ownership must be transferred.

Returns
Previously managed pointer. The caller is now responsible for managing its lifetime.

◆ serialize_formatted_json()

std::string launchdarkly::Value::serialize_formatted_json ( )
inline

Serializes the Value to formatted JSON string.

Returns
JSON string.

◆ serialize_json()

std::string launchdarkly::Value::serialize_json ( )
inline

Serializes the Value to a compact JSON string.

Returns
JSON string.

◆ type()

Type launchdarkly::Value::type ( ) const
inline

Returns the Value's type.

Returns
Type of Value.

The documentation for this class was generated from the following file: