MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Private Attributes | Friends
JSON::Value Class Reference

A JSON::Value is either a string or an integer, but may also be an object, array or null. More...

#include <json.h>

Public Member Functions

 Value ()
 Sets this JSON::Value to null;. More...
 
 Value ()
 
 Value (const Value &rhs)
 
 Value (const Value &rhs)
 
 Value (std::istream &fromstream)
 Sets this JSON::Value to read from this position in the std::istream. More...
 
 Value (std::istream &fromstream)
 
 Value (const std::string &val)
 Sets this JSON::Value to the given string. More...
 
 Value (const std::string &val)
 
 Value (const char *val)
 Sets this JSON::Value to the given string. More...
 
 Value (const char *val)
 
 Value (long long int val)
 Sets this JSON::Value to the given integer. More...
 
 Value (long long int val)
 
 Value (bool val)
 Sets this JSON::Value to the given integer. More...
 
 Value (bool val)
 
 ~Value ()
 Sets this JSON::Value to null. More...
 
 ~Value ()
 
void append (const Value &rhs)
 Appends the given value to the end of this JSON::Value array. More...
 
void append (const Value &rhs)
 
const bool asBool () const
 
const bool asBool () const
 Explicit conversion to bool. More...
 
const long long int asInt () const
 
const long long int asInt () const
 Explicit conversion to long long int. More...
 
const std::string asString () const
 
const std::string asString () const
 Explicit conversion to std::string. More...
 
const std::string & asStringRef () const
 
const std::string & asStringRef () const
 Explicit conversion to std::string reference. More...
 
const char * c_str () const
 
const char * c_str () const
 Explicit conversion to c-string. More...
 
bool isArray () const
 Returns true if this object is an array. More...
 
bool isArray () const
 
bool isBool () const
 Returns true if this object is a bool. More...
 
bool isBool () const
 
bool isInt () const
 Returns true if this object is an integer. More...
 
bool isInt () const
 
bool isMember (const std::string &name) const
 For object JSON::Value objects, returns true if the given name is a member. More...
 
bool isMember (const std::string &name) const
 
bool isNull () const
 Returns true if this object is null. More...
 
bool isNull () const
 
bool isObject () const
 
bool isObject () const
 Returns true if this object is an object. More...
 
bool isString () const
 
bool isString () const
 Returns true if this object is a string. More...
 
void netPrepare ()
 Pre-packs any object-type JSON::Value to a std::string for transfer over the network, including proper DTMI header. More...
 
void netPrepare ()
 
void null ()
 Completely clears the contents of this value, changing its type to NULL in the process. More...
 
void null ()
 
 operator bool () const
 
 operator bool () const
 Automatic conversion to bool. More...
 
 operator long long int () const
 
 operator long long int () const
 Automatic conversion to long long int - returns 0 if not convertable. More...
 
 operator std::string () const
 
 operator std::string () const
 Automatic conversion to std::string. More...
 
bool operator!= (const Value &rhs) const
 Compares a JSON::Value to another for equality. More...
 
bool operator!= (const Value &rhs) const
 
Valueoperator= (const Value &rhs)
 Sets this JSON::Value to be equal to the given JSON::Value. More...
 
Valueoperator= (const Value &rhs)
 
Valueoperator= (const std::string &rhs)
 Sets this JSON::Value to the given string. More...
 
Valueoperator= (const std::string &rhs)
 
Valueoperator= (const char *rhs)
 
Valueoperator= (const char *rhs)
 Sets this JSON::Value to the given string. More...
 
Valueoperator= (const long long int &rhs)
 
Valueoperator= (const long long int &rhs)
 Sets this JSON::Value to the given integer. More...
 
Valueoperator= (const int &rhs)
 
Valueoperator= (const int &rhs)
 Sets this JSON::Value to the given integer. More...
 
Valueoperator= (const unsigned int &rhs)
 
Valueoperator= (const unsigned int &rhs)
 Sets this JSON::Value to the given integer. More...
 
Valueoperator= (const bool &rhs)
 
Valueoperator= (const bool &rhs)
 Sets this JSON::Value to the given boolean. More...
 
bool operator== (const Value &rhs) const
 Compares a JSON::Value to another for equality. More...
 
bool operator== (const Value &rhs) const
 
Valueoperator[] (const std::string i)
 
Valueoperator[] (const std::string i)
 Retrieves or sets the JSON::Value at this position in the object. More...
 
Valueoperator[] (const char *i)
 
Valueoperator[] (const char *i)
 Retrieves or sets the JSON::Value at this position in the object. More...
 
Valueoperator[] (unsigned int i)
 
Valueoperator[] (unsigned int i)
 Retrieves or sets the JSON::Value at this position in the array. More...
 
const Valueoperator[] (const std::string i) const
 
const Valueoperator[] (const std::string i) const
 Retrieves the JSON::Value at this position in the object. More...
 
const Valueoperator[] (const char *i) const
 Retrieves the JSON::Value at this position in the object. More...
 
const Valueoperator[] (const char *i) const
 
const Valueoperator[] (unsigned int i) const
 
const Valueoperator[] (unsigned int i) const
 Retrieves the JSON::Value at this position in the array. More...
 
unsigned int packedSize () const
 Returns the packed size of this Value. More...
 
unsigned int packedSize () const
 
void prepend (const Value &rhs)
 Prepends the given value to the beginning of this JSON::Value array. More...
 
void prepend (const Value &rhs)
 
void removeMember (const std::string &name)
 
void removeMember (const std::string &name)
 For object JSON::Value objects, removes the member with the given name, if it exists. More...
 
void sendTo (Socket::Connection &socket) const
 Packs and transfers over the network. More...
 
void sendTo (Socket::Connection &socket) const
 
void shrink (unsigned int size)
 
void shrink (unsigned int size)
 For array and object JSON::Value objects, reduces them so they contain at most size elements, throwing away the first elements and keeping the last ones. More...
 
unsigned int size () const
 
unsigned int size () const
 Returns the total of the objects and array size combined. More...
 
std::string & toNetPacked ()
 
std::string & toNetPacked ()
 Packs any object-type JSON::Value to a std::string for transfer over the network, including proper DTMI header. More...
 
std::string toPacked () const
 
std::string toPacked () const
 Packs to a std::string for transfer over the network. More...
 
std::string toPrettyString (int indentation=0) const
 Converts this JSON::Value to valid JSON notation and returns it. More...
 
std::string toPrettyString (int indentation=0) const
 
std::string toString () const
 Converts this JSON::Value to valid JSON notation and returns it. More...
 
std::string toString () const
 

Private Attributes

std::deque< Value * > arrVal
 
long long int intVal
 
ValueType myType
 
std::map< std::string, Value * > objVal
 
std::string strVal
 

Friends

class ConstIter
 
class Iter
 

Detailed Description

A JSON::Value is either a string or an integer, but may also be an object, array or null.

Constructor & Destructor Documentation

JSON::Value::Value ( )

Sets this JSON::Value to null;.

JSON::Value::~Value ( )

Sets this JSON::Value to null.

JSON::Value::Value ( const Value rhs)
JSON::Value::Value ( std::istream &  fromstream)

Sets this JSON::Value to read from this position in the std::istream.

JSON::Value::Value ( const std::string &  val)

Sets this JSON::Value to the given string.

JSON::Value::Value ( const char *  val)

Sets this JSON::Value to the given string.

JSON::Value::Value ( long long int  val)

Sets this JSON::Value to the given integer.

JSON::Value::Value ( bool  val)

Sets this JSON::Value to the given integer.

JSON::Value::Value ( )
JSON::Value::~Value ( )
JSON::Value::Value ( const Value rhs)
JSON::Value::Value ( std::istream &  fromstream)
JSON::Value::Value ( const std::string &  val)
JSON::Value::Value ( const char *  val)
JSON::Value::Value ( long long int  val)
JSON::Value::Value ( bool  val)

Member Function Documentation

void JSON::Value::append ( const Value rhs)

Appends the given value to the end of this JSON::Value array.

Turns this value into an array if it is not already one.

void JSON::Value::append ( const Value rhs)
const bool JSON::Value::asBool ( ) const

Explicit conversion to bool.

const bool JSON::Value::asBool ( ) const
const long long int JSON::Value::asInt ( ) const

Explicit conversion to long long int.

const long long int JSON::Value::asInt ( ) const
const std::string JSON::Value::asString ( ) const
const std::string JSON::Value::asString ( ) const

Explicit conversion to std::string.

const std::string & JSON::Value::asStringRef ( ) const

Explicit conversion to std::string reference.

Returns a direct reference for string type JSON::Value objects, but a reference to a static empty string otherwise.

Warning
Only save to use when the JSON::Value is a string type!
const std::string& JSON::Value::asStringRef ( ) const
const char * JSON::Value::c_str ( ) const

Explicit conversion to c-string.

Returns a direct reference for string type JSON::Value objects, a reference to an empty string otherwise.

Warning
Only save to use when the JSON::Value is a string type!
const char* JSON::Value::c_str ( ) const
bool JSON::Value::isArray ( ) const

Returns true if this object is an array.

bool JSON::Value::isArray ( ) const
bool JSON::Value::isBool ( ) const

Returns true if this object is a bool.

bool JSON::Value::isBool ( ) const
bool JSON::Value::isInt ( ) const

Returns true if this object is an integer.

bool JSON::Value::isInt ( ) const
bool JSON::Value::isMember ( const std::string &  name) const

For object JSON::Value objects, returns true if the given name is a member.

Returns false otherwise.

bool JSON::Value::isMember ( const std::string &  name) const
bool JSON::Value::isNull ( ) const

Returns true if this object is null.

bool JSON::Value::isNull ( ) const
bool JSON::Value::isObject ( ) const

Returns true if this object is an object.

bool JSON::Value::isObject ( ) const
bool JSON::Value::isString ( ) const

Returns true if this object is a string.

bool JSON::Value::isString ( ) const
void JSON::Value::netPrepare ( )
void JSON::Value::netPrepare ( )

Pre-packs any object-type JSON::Value to a std::string for transfer over the network, including proper DTMI header.

Non-object-types will print an error. The internal buffer is guaranteed to be up-to-date after this function is called.

void JSON::Value::null ( )

Completely clears the contents of this value, changing its type to NULL in the process.

void JSON::Value::null ( )
JSON::Value::operator bool ( ) const
JSON::Value::operator bool ( ) const

Automatic conversion to bool.

Returns true if there is anything meaningful stored into this value.

JSON::Value::operator long long int ( ) const
JSON::Value::operator long long int ( ) const

Automatic conversion to long long int - returns 0 if not convertable.

JSON::Value::operator std::string ( ) const

Automatic conversion to std::string.

Returns the raw string value if available, otherwise calls toString().

JSON::Value::operator std::string ( ) const
bool JSON::Value::operator!= ( const Value rhs) const
bool JSON::Value::operator!= ( const Value rhs) const

Compares a JSON::Value to another for equality.

Value& JSON::Value::operator= ( const Value rhs)
JSON::Value & JSON::Value::operator= ( const Value rhs)

Sets this JSON::Value to be equal to the given JSON::Value.

JSON::Value & JSON::Value::operator= ( const std::string &  rhs)

Sets this JSON::Value to the given string.

Value& JSON::Value::operator= ( const std::string &  rhs)
Value& JSON::Value::operator= ( const char *  rhs)
JSON::Value & JSON::Value::operator= ( const char *  rhs)

Sets this JSON::Value to the given string.

JSON::Value & JSON::Value::operator= ( const long long int &  rhs)

Sets this JSON::Value to the given integer.

Value& JSON::Value::operator= ( const long long int &  rhs)
Value& JSON::Value::operator= ( const int &  rhs)
JSON::Value & JSON::Value::operator= ( const int &  rhs)

Sets this JSON::Value to the given integer.

JSON::Value & JSON::Value::operator= ( const unsigned int &  rhs)

Sets this JSON::Value to the given integer.

Value& JSON::Value::operator= ( const unsigned int &  rhs)
JSON::Value & JSON::Value::operator= ( const bool &  rhs)

Sets this JSON::Value to the given boolean.

Value& JSON::Value::operator= ( const bool &  rhs)
bool JSON::Value::operator== ( const Value rhs) const

Compares a JSON::Value to another for equality.

bool JSON::Value::operator== ( const Value rhs) const
JSON::Value & JSON::Value::operator[] ( const std::string  i)

Retrieves or sets the JSON::Value at this position in the object.

Converts destructively to object if not already an object.

Value& JSON::Value::operator[] ( const std::string  i)
JSON::Value & JSON::Value::operator[] ( const char *  i)

Retrieves or sets the JSON::Value at this position in the object.

Converts destructively to object if not already an object.

Value& JSON::Value::operator[] ( const char *  i)
JSON::Value & JSON::Value::operator[] ( unsigned int  i)

Retrieves or sets the JSON::Value at this position in the array.

Converts destructively to array if not already an array.

Value& JSON::Value::operator[] ( unsigned int  i)
const Value& JSON::Value::operator[] ( const std::string  i) const
const JSON::Value & JSON::Value::operator[] ( const std::string  i) const

Retrieves the JSON::Value at this position in the object.

Fails horribly if that values does not exist.

const Value& JSON::Value::operator[] ( const char *  i) const
const JSON::Value & JSON::Value::operator[] ( const char *  i) const

Retrieves the JSON::Value at this position in the object.

Fails horribly if that values does not exist.

const Value& JSON::Value::operator[] ( unsigned int  i) const
const JSON::Value & JSON::Value::operator[] ( unsigned int  i) const

Retrieves the JSON::Value at this position in the array.

Fails horribly if that values does not exist.

unsigned int JSON::Value::packedSize ( ) const
unsigned int JSON::Value::packedSize ( ) const

Returns the packed size of this Value.

void JSON::Value::prepend ( const Value rhs)
void JSON::Value::prepend ( const Value rhs)

Prepends the given value to the beginning of this JSON::Value array.

Turns this value into an array if it is not already one.

void JSON::Value::removeMember ( const std::string &  name)

For object JSON::Value objects, removes the member with the given name, if it exists.

Has no effect otherwise.

void JSON::Value::removeMember ( const std::string &  name)
void JSON::Value::sendTo ( Socket::Connection socket) const

Packs and transfers over the network.

If the object is a container type, this function will call itself recursively for all contents.

void JSON::Value::sendTo ( Socket::Connection socket) const
void JSON::Value::shrink ( unsigned int  size)

For array and object JSON::Value objects, reduces them so they contain at most size elements, throwing away the first elements and keeping the last ones.

Does nothing for other JSON::Value types, nor does it do anything if the size is already lower or equal to the given size.

void JSON::Value::shrink ( unsigned int  size)
unsigned int JSON::Value::size ( ) const

Returns the total of the objects and array size combined.

unsigned int JSON::Value::size ( ) const
std::string & JSON::Value::toNetPacked ( )

Packs any object-type JSON::Value to a std::string for transfer over the network, including proper DTMI header.

Non-object-types will print an error and return an empty string. This function returns a reference to an internal buffer where the prepared data is kept. The internal buffer is not made stale if any changes occur inside the object - subsequent calls to toPacked() will clear the buffer, calls to netPrepare will guarantee it is up-to-date.

std::string& JSON::Value::toNetPacked ( )
std::string JSON::Value::toPacked ( ) const

Packs to a std::string for transfer over the network.

If the object is a container type, this function will call itself recursively and contain all contents. As a side effect, this function clear the internal buffer of any object-types.

std::string JSON::Value::toPacked ( ) const
std::string JSON::Value::toPrettyString ( int  indentation = 0) const

Converts this JSON::Value to valid JSON notation and returns it.

Makes an attempt at pretty-printing.

std::string JSON::Value::toPrettyString ( int  indentation = 0) const
std::string JSON::Value::toString ( ) const

Converts this JSON::Value to valid JSON notation and returns it.

Makes absolutely no attempts to pretty-print anything. :-)

std::string JSON::Value::toString ( ) const

Friends And Related Function Documentation

ConstIter
friend
Iter
friend

Field Documentation

std::deque< Value * > JSON::Value::arrVal
private
long long int JSON::Value::intVal
private
ValueType JSON::Value::myType
private
std::map< std::string, Value * > JSON::Value::objVal
private
std::string JSON::Value::strVal
private

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