clan::JsonValue Class Reference

Class representing a JSON value. More...

#include <json_value.h>

Public Types

enum  Type {
  Type::undefined, Type::null, Type::object, Type::array,
  Type::string, Type::number, Type::boolean
}
 value type More...
 

Public Member Functions

Attributes
 operator bool () const
 Convert value to a different type. More...
 
 operator std::string () const
 
 operator float () const
 
 operator double () const
 
 operator int () const
 
JsonValueoperator[] (const char *key)
 Indexers for object members or array items. More...
 
JsonValueoperator[] (const std::string &key)
 
const JsonValueoperator[] (const char *key) const
 
const JsonValueoperator[] (const std::string &key) const
 
const JsonValueoperator[] (int index) const
 
JsonValueoperator[] (int index)
 
Type get_type () const
 Get value type. More...
 
size_t get_size () const
 Get size of value. More...
 
std::map< std::string, JsonValue > & get_members ()
 Get object members. More...
 
const std::map< std::string, JsonValue > & get_members () const
 
std::vector< JsonValue > & get_items ()
 Get array items. More...
 
const std::vector< JsonValue > & get_items () const
 
bool is_undefined () const
 Return true if value is undefined. More...
 
bool is_null () const
 Return true if value is null. More...
 
bool is_object () const
 Return true if value is an object. More...
 
bool is_array () const
 Return true if value is an array. More...
 
bool is_string () const
 Return true if value is a string. More...
 
bool is_number () const
 Return true if value is a number. More...
 
bool is_boolean () const
 Return true if value is a boolean. More...
 
std::string to_string () const
 Convert value object to a string. More...
 
int to_int () const
 Convert value object to an int. More...
 
float to_float () const
 Convert value object to a float. More...
 
double to_double () const
 Convert value object to a double. More...
 
bool to_boolean () const
 Convert value object to a boolean. More...
 
Operations
template<typename T >
JsonValueoperator= (const T &value)
 Assign a new value. More...
 
JsonValueoperator= (const JsonValue &value)
 
template<typename Type >
std::map< std::string, Typeto_map () const
 Convert value object to a std::map with the template specified value type. More...
 
template<typename Type >
std::vector< Typeto_vector () const
 Convert value array to a std::vector with the template specified value type. More...
 
std::string to_json () const
 Create an UTF-8 JSON string for the value. More...
 
void to_json (std::string &result) const
 

Construction

static JsonValue object ()
 Create a object value. More...
 
static JsonValue array ()
 Create a array value. More...
 
static JsonValue null ()
 Create a null value. More...
 
static JsonValue string (const std::string &value)
 Create a string value. More...
 
static JsonValue boolean (bool value)
 Create a boolean value. More...
 
static JsonValue number (int value)
 Create a number value. More...
 
static JsonValue number (double value)
 
static JsonValue from_json (const std::string &json)
 Create a value from UTF-8 JSON string. More...
 
 JsonValue ()
 Constructs a value. More...
 
 JsonValue (Type type)
 
 JsonValue (bool value)
 
 JsonValue (int value)
 
 JsonValue (double value)
 
 JsonValue (const char *value)
 
 JsonValue (const std::string &value)
 

Detailed Description

Class representing a JSON value.

Member Enumeration Documentation

◆ Type

enum clan::JsonValue::Type
strong

value type

Enumerator
undefined 
null 
object 
array 
string 
number 
boolean 

Constructor & Destructor Documentation

◆ JsonValue() [1/7]

clan::JsonValue::JsonValue ( )
inline

Constructs a value.

References clan::undefined.

Referenced by array(), boolean(), null(), number(), object(), operator=(), and string().

◆ JsonValue() [2/7]

clan::JsonValue::JsonValue ( Type  type)
inline

◆ JsonValue() [3/7]

clan::JsonValue::JsonValue ( bool  value)
inline

◆ JsonValue() [4/7]

clan::JsonValue::JsonValue ( int  value)
inline

◆ JsonValue() [5/7]

clan::JsonValue::JsonValue ( double  value)
inline

◆ JsonValue() [6/7]

clan::JsonValue::JsonValue ( const char *  value)
inline

◆ JsonValue() [7/7]

clan::JsonValue::JsonValue ( const std::string &  value)
inline

Member Function Documentation

◆ array()

static JsonValue clan::JsonValue::array ( )
inlinestatic

Create a array value.

References array, and JsonValue().

◆ boolean()

static JsonValue clan::JsonValue::boolean ( bool  value)
inlinestatic

Create a boolean value.

References JsonValue().

◆ from_json()

static JsonValue clan::JsonValue::from_json ( const std::string &  json)
static

Create a value from UTF-8 JSON string.

◆ get_items() [1/2]

std::vector<JsonValue>& clan::JsonValue::get_items ( )
inline

Get array items.

◆ get_items() [2/2]

const std::vector<JsonValue>& clan::JsonValue::get_items ( ) const
inline

◆ get_members() [1/2]

std::map<std::string, JsonValue>& clan::JsonValue::get_members ( )
inline

Get object members.

◆ get_members() [2/2]

const std::map<std::string, JsonValue>& clan::JsonValue::get_members ( ) const
inline

◆ get_size()

size_t clan::JsonValue::get_size ( ) const
inline

Get size of value.

References array, object, and string.

◆ get_type()

Type clan::JsonValue::get_type ( ) const
inline

Get value type.

◆ is_array()

bool clan::JsonValue::is_array ( ) const
inline

Return true if value is an array.

References array.

◆ is_boolean()

bool clan::JsonValue::is_boolean ( ) const
inline

Return true if value is a boolean.

References boolean.

◆ is_null()

bool clan::JsonValue::is_null ( ) const
inline

Return true if value is null.

References null.

◆ is_number()

bool clan::JsonValue::is_number ( ) const
inline

Return true if value is a number.

References number.

◆ is_object()

bool clan::JsonValue::is_object ( ) const
inline

Return true if value is an object.

References object.

◆ is_string()

bool clan::JsonValue::is_string ( ) const
inline

Return true if value is a string.

References string.

◆ is_undefined()

bool clan::JsonValue::is_undefined ( ) const
inline

Return true if value is undefined.

References undefined.

◆ null()

static JsonValue clan::JsonValue::null ( )
inlinestatic

Create a null value.

References JsonValue(), and null.

◆ number() [1/2]

static JsonValue clan::JsonValue::number ( double  value)
inlinestatic

References JsonValue().

◆ number() [2/2]

static JsonValue clan::JsonValue::number ( int  value)
inlinestatic

Create a number value.

References JsonValue().

◆ object()

static JsonValue clan::JsonValue::object ( )
inlinestatic

Create a object value.

References JsonValue(), and object.

Referenced by to_map().

◆ operator bool()

clan::JsonValue::operator bool ( ) const
inlineexplicit

Convert value to a different type.

References to_boolean().

◆ operator double()

clan::JsonValue::operator double ( ) const
inline

References to_double().

◆ operator float()

clan::JsonValue::operator float ( ) const
inline

References to_float().

◆ operator int()

clan::JsonValue::operator int ( ) const
inline

References to_int().

◆ operator std::string()

clan::JsonValue::operator std::string ( ) const
inline

References to_string().

◆ operator=() [1/2]

JsonValue& clan::JsonValue::operator= ( const JsonValue value)
inline

◆ operator=() [2/2]

template<typename T >
JsonValue& clan::JsonValue::operator= ( const T &  value)
inline

Assign a new value.

References JsonValue().

◆ operator[]() [1/6]

JsonValue& clan::JsonValue::operator[] ( const char *  key)
inline

Indexers for object members or array items.

◆ operator[]() [2/6]

const JsonValue& clan::JsonValue::operator[] ( const char *  key) const
inline

References clan::undefined.

◆ operator[]() [3/6]

JsonValue& clan::JsonValue::operator[] ( const std::string &  key)
inline

◆ operator[]() [4/6]

const JsonValue& clan::JsonValue::operator[] ( const std::string &  key) const
inline

References clan::undefined.

◆ operator[]() [5/6]

JsonValue& clan::JsonValue::operator[] ( int  index)
inline

◆ operator[]() [6/6]

const JsonValue& clan::JsonValue::operator[] ( int  index) const
inline

◆ string()

static JsonValue clan::JsonValue::string ( const std::string &  value)
inlinestatic

Create a string value.

References JsonValue().

◆ to_boolean()

bool clan::JsonValue::to_boolean ( ) const
inline

Convert value object to a boolean.

References boolean.

Referenced by operator bool().

◆ to_double()

double clan::JsonValue::to_double ( ) const
inline

Convert value object to a double.

References number.

Referenced by operator double().

◆ to_float()

float clan::JsonValue::to_float ( ) const
inline

Convert value object to a float.

References number.

Referenced by operator float().

◆ to_int()

int clan::JsonValue::to_int ( ) const
inline

Convert value object to an int.

References number.

Referenced by operator int().

◆ to_json() [1/2]

std::string clan::JsonValue::to_json ( ) const

Create an UTF-8 JSON string for the value.

◆ to_json() [2/2]

void clan::JsonValue::to_json ( std::string &  result) const

◆ to_map()

template<typename Type >
std::map<std::string, Type> clan::JsonValue::to_map ( ) const
inline

Convert value object to a std::map with the template specified value type.

References object.

◆ to_string()

std::string clan::JsonValue::to_string ( ) const
inline

Convert value object to a string.

References string.

Referenced by operator std::string().

◆ to_vector()

template<typename Type >
std::vector<Type> clan::JsonValue::to_vector ( ) const
inline

Convert value array to a std::vector with the template specified value type.

References array.


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