Twitch SDK (Internal)
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
ttv::json::Value Class Reference

Represents a JSON value. More...

#include <value.h>

Classes

struct  CommentInfo
 
class  CZString
 
union  ValueHolder
 

Public Types

typedef std::vector< std::string > Members
 
typedef ValueIterator iterator
 
typedef ValueConstIterator const_iterator
 
typedef json::UInt64 UInt
 
typedef json::Int64 Int
 
typedef UInt ArrayIndex
 
typedef std::map< CZString, ValueObjectValues
 

Public Member Functions

 Value (ValueType type=nullValue)
 Create a default Value of the given type. More...
 
 Value (Int value)
 
 Value (UInt value)
 
 Value (double value)
 
 Value (const char *value)
 
 Value (const char *beginValue, const char *endValue)
 
 Value (const StaticString &value)
 Constructs a value from a static string. More...
 
 Value (const std::string &value)
 
 Value (bool value)
 
 Value (const Value &other)
 
 ~Value ()
 
Valueoperator= (const Value &other)
 
void swap (Value &other)
 
ValueType type () const
 
bool operator< (const Value &other) const
 
bool operator<= (const Value &other) const
 
bool operator>= (const Value &other) const
 
bool operator> (const Value &other) const
 
bool operator== (const Value &other) const
 
bool operator!= (const Value &other) const
 
int compare (const Value &other)
 
const char * asCString () const
 
std::string asString () const
 
Int asInt () const
 
UInt asUInt () const
 
double asDouble () const
 
bool asBool () const
 
bool isNull () const
 
bool isBool () const
 
bool isInt () const
 
bool isUInt () const
 
bool isIntegral () const
 
bool isDouble () const
 
bool isNumeric () const
 
bool isString () const
 
bool isArray () const
 
bool isNonNullArray () const
 
bool isObject () const
 
bool isNonNullObject () const
 
bool isConvertibleTo (ValueType other) const
 
UInt size () const
 Number of values in array or object. More...
 
bool empty () const
 Return true if empty array, empty object, or null; otherwise, false. More...
 
bool operator! () const
 Return isNull() More...
 
void clear ()
 
void resize (UInt size)
 
Valueoperator[] (UInt index)
 
const Valueoperator[] (UInt index) const
 
Value get (UInt index, const Value &defaultValue) const
 
bool isValidIndex (UInt index) const
 Return true if index < size(). More...
 
Valueappend (const Value &value)
 Append value to array at the end. More...
 
Valueoperator[] (const char *key)
 Access an object value by name, create a null member if it does not exist. More...
 
const Valueoperator[] (const char *key) const
 Access an object value by name, returns null if there is no member with that name. More...
 
Valueoperator[] (const std::string &key)
 Access an object value by name, create a null member if it does not exist. More...
 
const Valueoperator[] (const std::string &key) const
 Access an object value by name, returns null if there is no member with that name. More...
 
Valueoperator[] (const StaticString &key)
 Access an object value by name, create a null member if it does not exist. More...
 
Value get (const char *key, const Value &defaultValue) const
 Return the member named key if it exist, defaultValue otherwise. More...
 
Value get (const std::string &key, const Value &defaultValue) const
 Return the member named key if it exist, defaultValue otherwise. More...
 
Value removeMember (const char *key)
 Remove and return the named member. More...
 
Value removeMember (const std::string &key)
 Same as removeMember(const char*) More...
 
bool isMember (const char *key) const
 Return true if the object has a member named key. More...
 
bool isMember (const std::string &key) const
 Return true if the object has a member named key. More...
 
Members getMemberNames () const
 Return a list of the member names. More...
 
void setComment (const char *comment, CommentPlacement placement)
 Comments must be //... or /* ... */. More...
 
void setComment (const std::string &comment, CommentPlacement placement)
 Comments must be //... or /* ... */. More...
 
bool hasComment (CommentPlacement placement) const
 
std::string getComment (CommentPlacement placement) const
 Include delimiters and embedded newlines. More...
 
std::string toStyledString () const
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 

Static Public Attributes

static const Value null
 
static const Int minInt
 
static const Int maxInt
 
static const UInt maxUInt
 

Private Member Functions

ValueresolveReference (const char *key, bool isStatic)
 

Private Attributes

union ttv::json::Value::ValueHolder value_
 
ValueType type_: 8
 
int allocated_: 1
 
CommentInfocomments_
 

Friends

class ValueIteratorBase
 

Detailed Description

Represents a JSON value.

This class is a discriminated union wrapper that can represents a:

The type of the held value is represented by a ValueType and can be obtained using type().

values of an objectValue or arrayValue can be accessed using operator[]() methods. Non const methods will automatically create the a nullValue element if it does not exist. The sequence of an arrayValue will be automatically resize and initialized with nullValue. resize() can be used to enlarge or truncate an arrayValue.

The get() methods can be used to obtanis default value in the case the required element does not exist.

It is possible to iterate over the list of a objectValue values using the getMemberNames() method.


Class Documentation

◆ ttv::json::Value::ValueHolder

union ttv::json::Value::ValueHolder
Class Members
bool bool_
Int int_
ObjectValues * map_
double real_
char * string_
UInt uint_

Member Typedef Documentation

◆ ArrayIndex

◆ const_iterator

◆ Int

◆ iterator

◆ Members

typedef std::vector<std::string> ttv::json::Value::Members

◆ ObjectValues

◆ UInt

Constructor & Destructor Documentation

◆ Value() [1/10]

ttv::json::Value::Value ( ValueType  type = nullValue)

Create a default Value of the given type.

This is a very useful constructor. To create an empty array, pass arrayValue. To create an empty object, pass objectValue. Another Value can then be set to this one by assignment. This is useful since clear() and resize() will not alter types.

Examples:
json::Value null_value; // null
json::Value arr_value(json::arrayValue); // []
json::Value obj_value(json::objectValue); // {}

◆ Value() [2/10]

ttv::json::Value::Value ( Int  value)

◆ Value() [3/10]

ttv::json::Value::Value ( UInt  value)

◆ Value() [4/10]

ttv::json::Value::Value ( double  value)

◆ Value() [5/10]

ttv::json::Value::Value ( const char *  value)

◆ Value() [6/10]

ttv::json::Value::Value ( const char *  beginValue,
const char *  endValue 
)

◆ Value() [7/10]

ttv::json::Value::Value ( const StaticString value)

Constructs a value from a static string.

Like other value string constructor but do not duplicate the string for internal storage. The given string must remain alive after the call to this constructor. Example of usage:

json::Value aValue( StaticString("some text") );

◆ Value() [8/10]

ttv::json::Value::Value ( const std::string &  value)

◆ Value() [9/10]

ttv::json::Value::Value ( bool  value)

◆ Value() [10/10]

ttv::json::Value::Value ( const Value other)

◆ ~Value()

ttv::json::Value::~Value ( )

Member Function Documentation

◆ append()

Value& ttv::json::Value::append ( const Value value)

Append value to array at the end.

Equivalent to jsonvalue[jsonvalue.size()] = value;

◆ asBool()

bool ttv::json::Value::asBool ( ) const

◆ asCString()

const char* ttv::json::Value::asCString ( ) const

◆ asDouble()

double ttv::json::Value::asDouble ( ) const

◆ asInt()

Int ttv::json::Value::asInt ( ) const

◆ asString()

std::string ttv::json::Value::asString ( ) const

◆ asUInt()

UInt ttv::json::Value::asUInt ( ) const

◆ begin() [1/2]

const_iterator ttv::json::Value::begin ( ) const

◆ begin() [2/2]

iterator ttv::json::Value::begin ( )

◆ clear()

void ttv::json::Value::clear ( )

Remove all object members and array elements.

Precondition
type() is arrayValue, objectValue, or nullValue
Postcondition
type() is unchanged

◆ compare()

int ttv::json::Value::compare ( const Value other)

◆ empty()

bool ttv::json::Value::empty ( ) const

Return true if empty array, empty object, or null; otherwise, false.

◆ end() [1/2]

const_iterator ttv::json::Value::end ( ) const

◆ end() [2/2]

iterator ttv::json::Value::end ( )

◆ get() [1/3]

Value ttv::json::Value::get ( UInt  index,
const Value defaultValue 
) const

If the array contains at least index+1 elements, returns the element value, otherwise returns defaultValue.

◆ get() [2/3]

Value ttv::json::Value::get ( const char *  key,
const Value defaultValue 
) const

Return the member named key if it exist, defaultValue otherwise.

◆ get() [3/3]

Value ttv::json::Value::get ( const std::string &  key,
const Value defaultValue 
) const

Return the member named key if it exist, defaultValue otherwise.

◆ getComment()

std::string ttv::json::Value::getComment ( CommentPlacement  placement) const

Include delimiters and embedded newlines.

◆ getMemberNames()

Members ttv::json::Value::getMemberNames ( ) const

Return a list of the member names.

If null, return an empty list.

Precondition
type() is objectValue or nullValue
Postcondition
if type() was nullValue, it remains nullValue

◆ hasComment()

bool ttv::json::Value::hasComment ( CommentPlacement  placement) const

◆ isArray()

bool ttv::json::Value::isArray ( ) const

◆ isBool()

bool ttv::json::Value::isBool ( ) const

◆ isConvertibleTo()

bool ttv::json::Value::isConvertibleTo ( ValueType  other) const

◆ isDouble()

bool ttv::json::Value::isDouble ( ) const

◆ isInt()

bool ttv::json::Value::isInt ( ) const

◆ isIntegral()

bool ttv::json::Value::isIntegral ( ) const

◆ isMember() [1/2]

bool ttv::json::Value::isMember ( const char *  key) const

Return true if the object has a member named key.

◆ isMember() [2/2]

bool ttv::json::Value::isMember ( const std::string &  key) const

Return true if the object has a member named key.

◆ isNonNullArray()

bool ttv::json::Value::isNonNullArray ( ) const

◆ isNonNullObject()

bool ttv::json::Value::isNonNullObject ( ) const

◆ isNull()

bool ttv::json::Value::isNull ( ) const

◆ isNumeric()

bool ttv::json::Value::isNumeric ( ) const

◆ isObject()

bool ttv::json::Value::isObject ( ) const

◆ isString()

bool ttv::json::Value::isString ( ) const

◆ isUInt()

bool ttv::json::Value::isUInt ( ) const

◆ isValidIndex()

bool ttv::json::Value::isValidIndex ( UInt  index) const

Return true if index < size().

◆ operator!()

bool ttv::json::Value::operator! ( ) const

Return isNull()

◆ operator!=()

bool ttv::json::Value::operator!= ( const Value other) const

◆ operator<()

bool ttv::json::Value::operator< ( const Value other) const

◆ operator<=()

bool ttv::json::Value::operator<= ( const Value other) const

◆ operator=()

Value& ttv::json::Value::operator= ( const Value other)

◆ operator==()

bool ttv::json::Value::operator== ( const Value other) const

◆ operator>()

bool ttv::json::Value::operator> ( const Value other) const

◆ operator>=()

bool ttv::json::Value::operator>= ( const Value other) const

◆ operator[]() [1/7]

Value& ttv::json::Value::operator[] ( UInt  index)

Access an array element (zero based index ). If the array contains less than index element, then null value are inserted in the array so that its size is index+1. (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.)

◆ operator[]() [2/7]

const Value& ttv::json::Value::operator[] ( UInt  index) const

Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.)

◆ operator[]() [3/7]

Value& ttv::json::Value::operator[] ( const char *  key)

Access an object value by name, create a null member if it does not exist.

◆ operator[]() [4/7]

const Value& ttv::json::Value::operator[] ( const char *  key) const

Access an object value by name, returns null if there is no member with that name.

◆ operator[]() [5/7]

Value& ttv::json::Value::operator[] ( const std::string &  key)

Access an object value by name, create a null member if it does not exist.

◆ operator[]() [6/7]

const Value& ttv::json::Value::operator[] ( const std::string &  key) const

Access an object value by name, returns null if there is no member with that name.

◆ operator[]() [7/7]

Value& ttv::json::Value::operator[] ( const StaticString key)

Access an object value by name, create a null member if it does not exist.

If the object as no entry for that name, then the member name used to store the new entry is not duplicated. Example of use:

json::Value object;
static const StaticString code("code");
object[code] = 1234;

◆ removeMember() [1/2]

Value ttv::json::Value::removeMember ( const char *  key)

Remove and return the named member.

Do nothing if it did not exist.

Returns
the removed Value, or null.
Precondition
type() is objectValue or nullValue
Postcondition
type() is unchanged

◆ removeMember() [2/2]

Value ttv::json::Value::removeMember ( const std::string &  key)

◆ resize()

void ttv::json::Value::resize ( UInt  size)

Resize the array to size elements. New elements are initialized to null. May only be called on nullValue or arrayValue.

Precondition
type() is arrayValue or nullValue
Postcondition
type() is arrayValue

◆ resolveReference()

Value& ttv::json::Value::resolveReference ( const char *  key,
bool  isStatic 
)
private

◆ setComment() [1/2]

void ttv::json::Value::setComment ( const char *  comment,
CommentPlacement  placement 
)

Comments must be //... or /* ... */.

◆ setComment() [2/2]

void ttv::json::Value::setComment ( const std::string &  comment,
CommentPlacement  placement 
)

Comments must be //... or /* ... */.

◆ size()

UInt ttv::json::Value::size ( ) const

Number of values in array or object.

◆ swap()

void ttv::json::Value::swap ( Value other)

Swap values.

Note
Currently, comments are intentionally not swapped, for both logic and efficiency.

◆ toStyledString()

std::string ttv::json::Value::toStyledString ( ) const

◆ type()

ValueType ttv::json::Value::type ( ) const

Friends And Related Function Documentation

◆ ValueIteratorBase

friend class ValueIteratorBase
friend

Member Data Documentation

◆ allocated_

int ttv::json::Value::allocated_
private

◆ comments_

CommentInfo* ttv::json::Value::comments_
private

◆ maxInt

const Int ttv::json::Value::maxInt
static

◆ maxUInt

const UInt ttv::json::Value::maxUInt
static

◆ minInt

const Int ttv::json::Value::minInt
static

◆ null

const Value ttv::json::Value::null
static

◆ type_

ValueType ttv::json::Value::type_
private

◆ value_

union ttv::json::Value::ValueHolder ttv::json::Value::value_
private

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