C++ Client-Side SDK
LaunchDarkly SDK
|
#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 | |
Value & | operator= (Value const &)=default |
Value & | operator= (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) |
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.
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:
launchdarkly::Value::Value | ( | char const * | str | ) |
Create a Value from a string constant.
str | The string constant to base the value on. |
launchdarkly::Value::Value | ( | ) |
Construct a value representing null.
launchdarkly::Value::Value | ( | bool | boolean | ) |
Construct a boolean value.
boolean |
launchdarkly::Value::Value | ( | double | num | ) |
Construct a number value from a double.
num |
launchdarkly::Value::Value | ( | int | num | ) |
Construct a number value from an integer.
num |
launchdarkly::Value::Value | ( | std::string | str | ) |
Construct a string value.
str |
launchdarkly::Value::Value | ( | std::vector< Value > | arr | ) |
Construct an array value from a vector of Value.
arr |
launchdarkly::Value::Value | ( | std::map< std::string, Value > | obj | ) |
Construct an object value from a map of Value.
obj |
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.
values |
launchdarkly::Value::Value | ( | std::optional< std::string > | opt_string | ) |
Create either a value string, or null value, from an optional string.
opt_string |
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.
bool launchdarkly::Value::AsBool | ( | ) | const |
If the value is a boolean, then return the boolean, otherwise return false.
int launchdarkly::Value::AsInt | ( | ) | const |
If the value is a number, then return the internal double value as an integer, otherwise return 0.
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.
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.
bool launchdarkly::Value::IsArray | ( | ) | const |
Returns true if the value is an array.
bool launchdarkly::Value::IsBool | ( | ) | const |
Returns true if the value is a boolean.
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.
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.
bool launchdarkly::Value::IsObject | ( | ) | const |
Returns true if the value is an object.
bool launchdarkly::Value::IsString | ( | ) | const |
Returns true if the value is a string.
|
static |
Get a null value.
enum Value::Type launchdarkly::Value::Type | ( | ) | const |
Get the type of the attribute.