CSCI3081W Drone Delivery System
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JsonValue Class Reference

Manages a picojson::value, provides implicit casting for valid JSON types. More...

#include <json.h>

Public Member Functions

 JsonValue ()
 Default constructor.
 
 JsonValue (picojson::value val)
 Create a JsonValue from an existing picojson::value (creates a copy) More...
 
 JsonValue (double d)
 Create a JsonValue from a double. More...
 
 JsonValue (int i)
 Create a JsonValue from an int. More...
 
 JsonValue (const std::string &s)
 Create a JsonValue from a string. More...
 
 JsonValue (const char *s)
 Create a JsonValue from a string literal. More...
 
 JsonValue (bool b)
 Create a JsonValue from a bool. More...
 
 JsonValue (const JsonObject &o)
 Create a JsonValue from a JsonObject. More...
 
 JsonValue (const JsonArray &a)
 Create a JsonValue from a JsonArray. More...
 
 ~JsonValue ()
 Destructor.
 
 JsonValue (const JsonValue &other)
 Copy constructor. More...
 
JsonValueoperator= (const JsonValue &other)
 Copy operator. More...
 
 JsonValue (JsonValue &&other)
 Move constructor. More...
 
JsonValueoperator= (JsonValue &&other) noexcept
 Move operator. More...
 
picojson::value & getValue ()
 
const picojson::value & getValue () const
 
 operator double () const
 
JsonValueoperator= (double d)
 set this value to a double More...
 
 operator float () const
 
JsonValueoperator= (float f)
 set this value to a float More...
 
 operator int () const
 
JsonValueoperator= (int i)
 set this value to an int More...
 
 operator std::string () const
 
JsonValueoperator= (const std::string &s)
 set this value to a string More...
 
JsonValueoperator= (const char *s)
 set this value to a string More...
 
 operator bool () const
 
JsonValueoperator= (bool b)
 set this value to a bool More...
 
 operator JsonObject () const
 
JsonValueoperator= (const JsonObject &o)
 set this value to a JsonObject More...
 
 operator JsonArray () const
 
JsonValueoperator= (const JsonArray &a)
 set this value to a JsonArray More...
 
std::string toString () const
 Serialize this to valid JSON text. More...
 

Static Public Member Functions

static JsonValue fromReference (picojson::value &v)
 Create a a JsonValue using a reference to an existing picojson::value. Instead of creating a copy of the picojson::value, this just stores a reference to it. This is only needed for internal use. More...
 

Protected Member Functions

template<class T >
get () const
 Gets the value from the specific template.
 
template<class T >
void set (const T &t)
 Sets the value from the specific template. More...
 

Protected Attributes

union {
   picojson::value   v
 
   std::reference_wrapper< picojson::value >   ref
 
}; 
 
bool isRef = false
 

Detailed Description

Manages a picojson::value, provides implicit casting for valid JSON types.

Constructor & Destructor Documentation

◆ JsonValue() [1/10]

JsonValue::JsonValue ( picojson::value  val)
inline

Create a JsonValue from an existing picojson::value (creates a copy)

Parameters
valpicojson:value to copy

◆ JsonValue() [2/10]

JsonValue::JsonValue ( double  d)
inline

Create a JsonValue from a double.

Parameters
da double

◆ JsonValue() [3/10]

JsonValue::JsonValue ( int  i)
inline

Create a JsonValue from an int.

Parameters
ian int

◆ JsonValue() [4/10]

JsonValue::JsonValue ( const std::string &  s)
inline

Create a JsonValue from a string.

Parameters
sa string

◆ JsonValue() [5/10]

JsonValue::JsonValue ( const char *  s)
inline

Create a JsonValue from a string literal.

Parameters
sa string literal

◆ JsonValue() [6/10]

JsonValue::JsonValue ( bool  b)
inline

Create a JsonValue from a bool.

Parameters
ba bool

◆ JsonValue() [7/10]

JsonValue::JsonValue ( const JsonObject o)

Create a JsonValue from a JsonObject.

Parameters
oa JsonObject

◆ JsonValue() [8/10]

JsonValue::JsonValue ( const JsonArray &  a)

Create a JsonValue from a JsonArray.

Parameters
aa JsonArray

◆ JsonValue() [9/10]

JsonValue::JsonValue ( const JsonValue other)

Copy constructor.

Parameters
otheranother JsonValue

◆ JsonValue() [10/10]

JsonValue::JsonValue ( JsonValue &&  other)

Move constructor.

Parameters
otheranother JsonValue

Member Function Documentation

◆ fromReference()

static JsonValue JsonValue::fromReference ( picojson::value &  v)
static

Create a a JsonValue using a reference to an existing picojson::value. Instead of creating a copy of the picojson::value, this just stores a reference to it. This is only needed for internal use.

Parameters
va picojson::value to create a reference to
Returns
the new JsonValue

◆ getValue() [1/2]

picojson::value& JsonValue::getValue ( )
inline
Returns
The underlying picojson::value

◆ getValue() [2/2]

const picojson::value& JsonValue::getValue ( ) const
inline
Returns
The underlying picojson::value

◆ operator bool()

JsonValue::operator bool ( ) const
inline
Returns
Converts this to a bool

◆ operator double()

JsonValue::operator double ( ) const
inline
Returns
Converts this to a double

◆ operator float()

JsonValue::operator float ( ) const
inline
Returns
Converts this to a float

◆ operator int()

JsonValue::operator int ( ) const
inline
Returns
Converts this to an int

◆ operator JsonArray()

JsonValue::operator JsonArray ( ) const
Returns
Converts this to a JsonArray

◆ operator JsonObject()

JsonValue::operator JsonObject ( ) const
Returns
Converts this to a JsonObject

◆ operator std::string()

JsonValue::operator std::string ( ) const
inline
Returns
Converts this to a string

◆ operator=() [1/10]

JsonValue& JsonValue::operator= ( bool  b)
inline

set this value to a bool

Returns
this

◆ operator=() [2/10]

JsonValue& JsonValue::operator= ( const char *  s)
inline

set this value to a string

Returns
this

◆ operator=() [3/10]

JsonValue& JsonValue::operator= ( const JsonArray &  a)

set this value to a JsonArray

Returns
this

◆ operator=() [4/10]

JsonValue& JsonValue::operator= ( const JsonObject o)

set this value to a JsonObject

Returns
this

◆ operator=() [5/10]

JsonValue& JsonValue::operator= ( const JsonValue other)

Copy operator.

Parameters
otheranother JsonValue
Returns
this

◆ operator=() [6/10]

JsonValue& JsonValue::operator= ( const std::string &  s)
inline

set this value to a string

Returns
this

◆ operator=() [7/10]

JsonValue& JsonValue::operator= ( double  d)
inline

set this value to a double

Returns
this

◆ operator=() [8/10]

JsonValue& JsonValue::operator= ( float  f)
inline

set this value to a float

Returns
this

◆ operator=() [9/10]

JsonValue& JsonValue::operator= ( int  i)
inline

set this value to an int

Returns
this

◆ operator=() [10/10]

JsonValue& JsonValue::operator= ( JsonValue &&  other)
noexcept

Move operator.

Parameters
otheranother JsonValue
Returns
this

◆ set()

template<class T >
void JsonValue::set ( const T &  t)
inlineprotected

Sets the value from the specific template.

Parameters
tThe specific template

◆ toString()

std::string JsonValue::toString ( ) const
inline

Serialize this to valid JSON text.

Returns
This as a serialized JSON-formatted string.

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