clan::JsonValue Class Reference

Class representing a JSON value. More...

#include <json_value.h>

Public Types

enum  Type {
  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 double () const
 
 operator int () const
 
JsonValueoperator[] (const char *key)
 Indexers for object members or array items. More...
 
JsonValueoperator[] (const std::string &key)
 
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_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
JsonValueoperator= (const std::string &value)
 Assign a new value. More...
 
JsonValueoperator= (int value)
 
JsonValueoperator= (double value)
 
JsonValueoperator= (bool &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 (const std::string &value)
 
 JsonValue (int value)
 
 JsonValue (double value)
 
 JsonValue (bool value)
 

Detailed Description

Class representing a JSON value.

Member Enumeration Documentation

value type

Enumerator
type_null 
type_object 
type_array 
type_string 
type_number 
type_boolean 

Constructor & Destructor Documentation

clan::JsonValue::JsonValue ( )
inline

Constructs a value.

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

clan::JsonValue::JsonValue ( Type  type)
inline
clan::JsonValue::JsonValue ( const std::string &  value)
inline
clan::JsonValue::JsonValue ( int  value)
inline
clan::JsonValue::JsonValue ( double  value)
inline
clan::JsonValue::JsonValue ( bool  value)
inlineexplicit

Member Function Documentation

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

Create a array value.

References JsonValue(), and type_array.

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

Create a boolean value.

References JsonValue().

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

Create a value from UTF-8 JSON string.

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

Get array items.

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

Get object members.

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

Get size of value.

References type_array, type_object, and type_string.

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

Get value type.

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

Return true if value is an array.

References type_array.

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

Return true if value is a boolean.

References type_boolean.

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

Return true if value is null.

References type_null.

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

Return true if value is a number.

References type_number.

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

Return true if value is an object.

References type_object.

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

Return true if value is a string.

References type_string.

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

Create a null value.

References JsonValue(), and type_null.

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

Create a number value.

References JsonValue().

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

References JsonValue().

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

Create a object value.

References JsonValue(), and type_object.

Referenced by to_map().

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

Convert value to a different type.

References to_boolean().

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

References to_double().

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

References to_int().

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

References to_string().

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

Assign a new value.

References JsonValue().

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

References JsonValue().

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

References JsonValue().

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

References JsonValue().

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

Indexers for object members or array items.

JsonValue& clan::JsonValue::operator[] ( const std::string &  key)
inline
const JsonValue& clan::JsonValue::operator[] ( int  index) const
inline
JsonValue& clan::JsonValue::operator[] ( int  index)
inline
static JsonValue clan::JsonValue::string ( const std::string &  value)
inlinestatic

Create a string value.

References JsonValue().

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

Convert value object to a boolean.

References type_boolean.

Referenced by operator bool().

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

Convert value object to a double.

References type_number.

Referenced by operator double().

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

Convert value object to a float.

References type_number.

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

Convert value object to an int.

References type_number.

Referenced by operator int().

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

Create an UTF-8 JSON string for the value.

void clan::JsonValue::to_json ( std::string &  result) const
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(), and type_object.

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

Convert value object to a string.

References type_string.

Referenced by operator std::string().

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 type_array.


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