C++ Client-Side SDK
LaunchDarkly SDK
Typedefs | Enumerations | Functions
value.h File Reference
#include <stdbool.h>
#include <launchdarkly/bindings/c/export.h>
Include dependency graph for value.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct _LDValue * LDValue
 
typedef struct _LDValue_ObjectIter * LDValue_ObjectIter
 
typedef struct _LDValue_ArrayIter * LDValue_ArrayIter
 

Enumerations

enum  LDValueType {
  LDValueType_Null , LDValueType_Bool , LDValueType_Number , LDValueType_String ,
  LDValueType_Array , LDValueType_Object
}
 

Functions

 LDValue_NewNull ()
 
 LDValue_NewBool (bool val)
 
 LDValue_NewNumber (double val)
 
 LDValue_NewString (char const *val)
 
 LDValue_NewValue (LDValue val)
 
 LDValue_Free (LDValue val)
 
 LDValue_Type (LDValue val)
 
 LDValue_GetBool (LDValue val)
 
 LDValue_GetNumber (LDValue val)
 
 LDValue_GetString (LDValue val)
 
 LDValue_Count (LDValue val)
 
 LDValue_SerializeJSON (LDValue val)
 
 LDValue_ArrayIter_New (LDValue val)
 
 LDValue_ArrayIter_Next (LDValue_ArrayIter iter)
 
 LDValue_ArrayIter_End (LDValue_ArrayIter iter)
 
 LDValue_ArrayIter_Value (LDValue_ArrayIter iter)
 
 LDValue_ArrayIter_Free (LDValue_ArrayIter iter)
 
 LDValue_ObjectIter_New (LDValue val)
 
 LDValue_ObjectIter_Next (LDValue_ObjectIter iter)
 
 LDValue_ObjectIter_End (LDValue_ObjectIter iter)
 
 LDValue_ObjectIter_Value (LDValue_ObjectIter iter)
 
 LDValue_ObjectIter_Key (LDValue_ObjectIter iter)
 
 LDValue_ObjectIter_Free (LDValue_ObjectIter iter)
 

Typedef Documentation

◆ LDValue

typedef struct _LDValue* LDValue

Value represents any of the data types supported by JSON, all of which can be used for a LaunchDarkly feature flag variation, or for an attribute in an evaluation context. Value instances are immutable.

A basic LDValue types can be created directly using the LDValue_New* methods. This includes: null-type, boolean-type, number-type, and string-type.

An array-type or object-type LDValue must be created using LDArrayBuilder_New() or LDObjectBuilder_New().

Basic LDValue types can be converted to raw types using the LDValue_Get* methods.

Accessing the members of object-type or array-type type must be done using iteration.

◆ LDValue_ArrayIter

typedef struct _LDValue_ArrayIter* LDValue_ArrayIter

LDValue_ArrayIter is a handle to an iterator, bound to an LDValue. It can be used to obtain the values of an array.

The iterator must be destroyed after use using LDValue_ArrayIter_Free. An iterator for an LDValue that has been freed should not be used.

◆ LDValue_ObjectIter

typedef struct _LDValue_ObjectIter* LDValue_ObjectIter

LDValue_ObjectIter is a handle to an iterator, bound to an LDValue. It can be used to obtain the keys and values of an object.

The iterator must be destroyed after use using LDValue_ObjectIter_Free. An iterator for an LDValue that has been freed should not be used.

Enumeration Type Documentation

◆ LDValueType

Describes the type of an LDValue. These correspond to the standard types in JSON.

Enumerator
LDValueType_Null 

The value is null.

LDValueType_Bool 

The value is a boolean.

LDValueType_Number 

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

LDValueType_String 

The value is a string.

LDValueType_Array 

The value is an array.

LDValueType_Object 

The value is an object.

Function Documentation

◆ LDValue_ArrayIter_End()

LDValue_ArrayIter_End ( LDValue_ArrayIter  iter)

Check if an array-type iterator is at the end.

Parameters
iterThe iterator to check. Must not be NULL.
Returns
True if the iterator is at the end.

◆ LDValue_ArrayIter_Free()

LDValue_ArrayIter_Free ( LDValue_ArrayIter  iter)

Destroy an array iterator.

Parameters
iterThe iterator to destroy.

◆ LDValue_ArrayIter_New()

LDValue_ArrayIter_New ( LDValue  val)

Obtain iterator over an array-type LDValue, otherwise NULL.

The iterator starts at the first element.

Parameters
valTarget LDValue. Must not be NULL.
Returns
Iterator, or NULL if not an array-type. The iterator must should be destroyed with LDValue_ArrayIter_Free().

◆ LDValue_ArrayIter_Next()

LDValue_ArrayIter_Next ( LDValue_ArrayIter  iter)

Move the array-type iterator to the next item. Should only be done for an iterator which is not at the end.

Parameters
iterThe iterator to advance. Must not be NULL.

◆ LDValue_ArrayIter_Value()

LDValue_ArrayIter_Value ( LDValue_ArrayIter  iter)

Get the value for the array-type iterator. The value's lifetime is valid only for as long as the iterator. To obtain a copy, call LDValue_NewValue with the result.

Parameters
iterThe iterator to get a value for. Must not be NULL.
Returns
The value reference.

◆ LDValue_Count()

LDValue_Count ( LDValue  val)

Obtain number of LDValue elements stored in an array-type LDValue, or number of key/LDValue pairs stored in an object-type LDValue.

If not an array-type or object-type, returns 0.

Parameters
valTarget LDValue. Must not be NULL.
Returns
Count of LDValue elements, or 0 if not array-type/object-type.

◆ LDValue_Free()

LDValue_Free ( LDValue  val)

Frees an LDValue.

An LDValue should only be freed when directly owned by the caller, i.e., it was never moved into an array or object builder.

Parameters
valLDValue to free.

◆ LDValue_GetBool()

LDValue_GetBool ( LDValue  val)

Obtain value of a boolean-type LDValue, otherwise returns false.

Parameters
valTarget LDValue. Must not be NULL.
Returns
Boolean value, or false if not boolean-type.

◆ LDValue_GetNumber()

LDValue_GetNumber ( LDValue  val)

Obtain value of a number-type LDValue, otherwise return 0.

Parameters
valTarget LDValue. Must not be NULL.
Returns
Number value, or 0 if not number-type.

◆ LDValue_GetString()

LDValue_GetString ( LDValue  val)

Obtain value of a string-type LDValue, otherwise returns pointer to an empty string.

The returned string is only valid for the lifetime of the LDValue. If you need the string outside this lifetime, then a copy should be made.

Parameters
valTarget LDValue. Must not be NULL.
Returns
String value, or empty string if not string-type.

◆ LDValue_NewBool()

LDValue_NewBool ( bool  val)

Allocates a new boolean-type LDValue.

Parameters
valBoolean.
Returns
New LDValue.

◆ LDValue_NewNull()

LDValue_NewNull ( )

Allocates a new null-type LDValue. WARNING! A NULL pointer is not a valid LDValue; to represent null (the JSON type), use this constructor.

Returns
New LDValue.

◆ LDValue_NewNumber()

LDValue_NewNumber ( double  val)

Allocates a new number-type LDValue.

Parameters
valDouble value.
Returns
New LDValue.

◆ LDValue_NewString()

LDValue_NewString ( char const *  val)

Allocates a new string-type LDValue.

The input string will be copied.

Parameters
valConstant reference to a string. The string is copied. Must not be NULL.
Returns
New LDValue.

◆ LDValue_NewValue()

LDValue_NewValue ( LDValue  val)

Allocates an LDValue by cloning an existing LDValue.

Parameters
valThe source value. Must not be NULL.
Returns
New LDValue.

◆ LDValue_ObjectIter_End()

LDValue_ObjectIter_End ( LDValue_ObjectIter  iter)

Check if an object-type iterator is at the end.

Parameters
iterThe iterator to check. Must not be NULL.
Returns
True if the iterator is at the end.

◆ LDValue_ObjectIter_Free()

LDValue_ObjectIter_Free ( LDValue_ObjectIter  iter)

Destroy an object iterator.

Parameters
iterThe iterator to destroy.

◆ LDValue_ObjectIter_Key()

LDValue_ObjectIter_Key ( LDValue_ObjectIter  iter)

Get the key for an object-type iterator.

The returned key has a lifetime attached to that of the LDValue.

Parameters
iterThe iterator to get a key for. Must not be NULL.
Returns
The key.

◆ LDValue_ObjectIter_New()

LDValue_ObjectIter_New ( LDValue  val)

Obtain iterator over an object-type LDValue, otherwise NULL.

The iterator starts at the first element.

Parameters
valTarget LDValue. Must not be NULL.
Returns
Iterator, or NULL if not an object-type. The iterator must should be destroyed with LDValue_ObjectIter_Free().

◆ LDValue_ObjectIter_Next()

LDValue_ObjectIter_Next ( LDValue_ObjectIter  iter)

Move the object-type iterator to the next item. Should only be done for an iterator which is not at the end.

Parameters
iterThe iterator to advance. Must not be NULL.

◆ LDValue_ObjectIter_Value()

LDValue_ObjectIter_Value ( LDValue_ObjectIter  iter)

Get the value for an object-type iterator. The value's lifetime is valid only for as long as the iterator. To obtain a copy, call LDValue_NewValue.

Parameters
iterThe iterator to get a value for. Must not be NULL.
Returns
The value.

◆ LDValue_SerializeJSON()

LDValue_SerializeJSON ( LDValue  val)

Serializes the LDValue to a JSON value. The returning string should be freed with LDMemory_FreeString.

Please note that numbers are serialized using scientific notation; for example the number 17 would be serialized as '1.7E1'.

Parameters
valTarget LDValue. Must not be NULL.
Returns
A string containing the JSON representation of the LDValue. The string should be freed with LDMemory_FreeString.

◆ LDValue_Type()

LDValue_Type ( LDValue  val)

Returns the type of an LDValue.

Parameters
valLDValue to inspect. Must not be NULL.
Returns
Type of the LDValue, or LDValueType_Unrecognized if the type is unrecognized.