C++ Client-Side SDK
LaunchDarkly SDK
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
launchdarkly::Value Class Referencefinal

#include <value.hpp>

Classes

class  Array
 
class  Object
 

Public Types

enum class  Type {
  kNull , kBool , kNumber , kString ,
  kObject , kArray
}
 

Public Member Functions

 Value (char const *str)
 
 Value ()
 
 Value (Value const &val)=default
 
 Value (Value &&)=default
 
Valueoperator= (Value const &)=default
 
Valueoperator= (Value &&)=default
 
 Value (bool boolean)
 
 Value (double num)
 
 Value (int num)
 
 Value (std::string str)
 
 Value (std::vector< Value > arr)
 
 Value (Array arr)
 
 Value (Object obj)
 
 Value (std::map< std::string, Value > obj)
 
 Value (std::initializer_list< Value > values)
 
 Value (std::optional< std::string > opt_string)
 
Type Type () const
 
bool IsNull () const
 
bool IsBool () const
 
bool IsNumber () const
 
bool IsString () const
 
bool IsArray () const
 
bool IsObject () const
 
bool AsBool () const
 
int AsInt () const
 
double AsDouble () const
 
std::string const & AsString () const
 
Array const & AsArray () const
 
Object const & AsObject () const
 
 operator bool () const
 
 operator std::string () const
 
 operator double () const
 
 operator int () const
 

Static Public Member Functions

static Value const & Null ()
 

Friends

std::ostream & operator<< (std::ostream &out, Value const &value)
 

Detailed Description

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.

Uses of JSON types in LaunchDarkly

LaunchDarkly feature flags can have variations of any JSON type other than null. If you want to evaluate a feature flag in a general way that does not have expectations about the variation type, or if the variation value is a complex data structure such as an array or object, you can use the SDK method launchdarkly::client_side::IClient::JsonVariation.

Similarly, attributes of an evaluation context (launchdarkly::Context) can have variations of any JSON type other than null. If you want to set a context attribute in a general way that will accept any type, or set the attribute value to a complex data structure such as an array or object, you can use the builder method launchdarkly::AttributesBuilder< BuilderReturn, BuildType >::set.

Arrays and objects have special meanings in LaunchDarkly flag evaluation:

Constructor & Destructor Documentation

◆ Value() [1/10]

launchdarkly::Value::Value ( char const *  str)

Create a Value from a string constant.

Parameters
strThe string constant to base the value on.

◆ Value() [2/10]

launchdarkly::Value::Value ( )

Construct a value representing null.

◆ Value() [3/10]

launchdarkly::Value::Value ( bool  boolean)

Construct a boolean value.

Parameters
boolean

◆ Value() [4/10]

launchdarkly::Value::Value ( double  num)

Construct a number value from a double.

Parameters
num

◆ Value() [5/10]

launchdarkly::Value::Value ( int  num)

Construct a number value from an integer.

Parameters
num

◆ Value() [6/10]

launchdarkly::Value::Value ( std::string  str)

Construct a string value.

Parameters
str

◆ Value() [7/10]

launchdarkly::Value::Value ( std::vector< Value arr)

Construct an array value from a vector of Value.

Parameters
arr

◆ Value() [8/10]

launchdarkly::Value::Value ( std::map< std::string, Value obj)

Construct an object value from a map of Value.

Parameters
obj

◆ Value() [9/10]

launchdarkly::Value::Value ( std::initializer_list< Value values)

Create an array type value from the given list.

Cannot be used to create object type values.

Parameters
values

◆ Value() [10/10]

launchdarkly::Value::Value ( std::optional< std::string >  opt_string)

Create either a value string, or null value, from an optional string.

Parameters
opt_string

Member Function Documentation

◆ AsArray()

Value::Array const & launchdarkly::Value::AsArray ( ) const

If the value is an array type, then return a reference to that array as a vector, otherwise return a reference to an empty vector.

Returns
The value as a vector, or an empty vector.

◆ AsBool()

bool launchdarkly::Value::AsBool ( ) const

If the value is a boolean, then return the boolean, otherwise return false.

Returns
The value of the boolean, or false.

◆ AsInt()

int launchdarkly::Value::AsInt ( ) const

If the value is a number, then return the internal double value as an integer, otherwise return 0.

Returns
The value as an integer, or 0.

◆ AsObject()

Value::Object const & launchdarkly::Value::AsObject ( ) const

if the value is an object type, then return a reference to that object as a map, otherwise return a reference to an empty map.

Returns
The value as a map, or an empty map.

◆ AsString()

std::string const & launchdarkly::Value::AsString ( ) const

If the value is a string, then return a reference to that string, otherwise return a reference to an empty string.

Returns
The value as a string, or an empty string.

◆ IsArray()

bool launchdarkly::Value::IsArray ( ) const

Returns true if the value is an array.

Returns
True if the value is an array.

◆ IsBool()

bool launchdarkly::Value::IsBool ( ) const

Returns true if the value is a boolean.

Returns

◆ IsNull()

bool launchdarkly::Value::IsNull ( ) const

Returns true if the value is a null.

Unlike other variants there is not an as_null(). Instead use the return value from this function as a marker.

Returns
True if the value is null.

◆ IsNumber()

bool launchdarkly::Value::IsNumber ( ) const

Returns true if the value is a number.

Numbers are always stored as doubles, but can be accessed as either an int or double for convenience.

Returns
True if the value is a number.

◆ IsObject()

bool launchdarkly::Value::IsObject ( ) const

Returns true if the value is an object.

Returns
True if the value is an object.

◆ IsString()

bool launchdarkly::Value::IsString ( ) const

Returns true if the value is a string.

Returns
True if the value is a string.

◆ Null()

Value const & launchdarkly::Value::Null ( )
static

Get a null value.

Returns
The null value.

◆ Type()

enum Value::Type launchdarkly::Value::Type ( ) const

Get the type of the attribute.


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