ChessPlusPlus  WIP
cplusplus.com Community Project
chesspp::util::JsonReader::NestedValue Class Reference

#include <JsonReader.hpp>

Public Member Functions

 NestedValue (NestedValue const &)=default
 
 NestedValue (NestedValue &&)=default
 
NestedValueoperator= (NestedValue &&)=default
 
 ~NestedValue ()=default
 
json_type type () const noexcept
 
NestedValue parent () const
 
NestedValue operator[] (std::string const &name) const noexcept(noexcept(name.c_str()))
 
NestedValue operator[] (char const *name) const
 
std::size_t length () const noexcept
 
NestedValue operator[] (std::size_t index) const noexcept
 
std::map< std::string, NestedValueobject () const
 
 operator std::string () const noexcept(noexcept(std::string("")))
 
 operator std::int8_t () const noexcept
 
 operator std::uint8_t () const noexcept
 
 operator std::int16_t () const noexcept
 
 operator std::uint16_t () const noexcept
 
 operator std::int32_t () const noexcept
 
 operator std::uint32_t () const noexcept
 
 operator std::int64_t () const noexcept
 
 operator std::uint64_t () const noexcept
 
 operator bool () const noexcept
 
 operator double () const noexcept
 
json_value const & implementation () noexcept
 

Friends

class ::chesspp::util::JsonReader
 

Detailed Description

Represents a value in the JSON. Instances of this class should not exceed the lifetime of the JsonReader that they came from. Attempting to access a NestedValue for which the associated JsonReader has been destructed results in undefined behavior. Two or more instances of this class may represent the same nested value in the JSON.

Constructor & Destructor Documentation

chesspp::util::JsonReader::NestedValue::NestedValue ( NestedValue const &  )
default
chesspp::util::JsonReader::NestedValue::NestedValue ( NestedValue &&  )
default
chesspp::util::JsonReader::NestedValue::~NestedValue ( )
default

Member Function Documentation

json_value const& chesspp::util::JsonReader::NestedValue::implementation ( )
inlinenoexcept

Only for extreme use cases: returns the underlying json_value being wrapped.

Returns
the underlying json_value
std::size_t chesspp::util::JsonReader::NestedValue::length ( ) const
inlinenoexcept

Returns the length of array values.

Returns
The length of the array, or 0 if not an array.
std::map<std::string, NestedValue> chesspp::util::JsonReader::NestedValue::object ( ) const
inline

Provides a std::map-based view of an object value, mapping object keys to object values. Only works if type() == json_object

Returns
a std::map of object keys ot obejct values
chesspp::util::JsonReader::NestedValue::operator bool ( ) const
inlinenoexcept

Returns the boolean state of this bool value. Only works if type() == json_bool.

Returns
The boolean.
chesspp::util::JsonReader::NestedValue::operator double ( ) const
inlinenoexcept

Returns the floating-point value of this double. Only works if type() == json_double

Returns
The double.
chesspp::util::JsonReader::NestedValue::operator std::int16_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::int32_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::int64_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::int8_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::string ( ) const
inlinenoexcept

Returns the string representation of this string value. Only works if type() == json_string

Returns
The string
chesspp::util::JsonReader::NestedValue::operator std::uint16_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::uint32_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::uint64_t ( ) const
inlinenoexcept
chesspp::util::JsonReader::NestedValue::operator std::uint8_t ( ) const
inlinenoexcept
NestedValue& chesspp::util::JsonReader::NestedValue::operator= ( NestedValue &&  )
default
NestedValue chesspp::util::JsonReader::NestedValue::operator[] ( std::string const &  name) const
inlinenoexcept

Returns a NestedValue within this one by name. Only works if type() == json_object

Parameters
namethe name of the nested JSON value.
Returns
the NestedValue by name.
NestedValue chesspp::util::JsonReader::NestedValue::operator[] ( char const *  name) const
inline

Returns a NestedValue within this one by name. Only works if type() == json_object

Parameters
namethe name of the nested JSON value.
Returns
the NestedValue by name.
NestedValue chesspp::util::JsonReader::NestedValue::operator[] ( std::size_t  index) const
inlinenoexcept

Returns the nested value at the given array index. Only works if type() == json_array

Parameters
indexThe index within the array.
Returns
the nested value at the given index.
NestedValue chesspp::util::JsonReader::NestedValue::parent ( ) const
inline

Returns the parent NestedValue or throws chesspp::Exception.

Returns
the parent NestedValue.
Exceptions
chesspp::Exception
json_type chesspp::util::JsonReader::NestedValue::type ( ) const
inlinenoexcept

Returns the type of this value. Note that the return value is a type from the json-parse library. It may be compared to these constants: json_null json_boolean json_integer json_double json_string json_array json_object

Returns
The type of value represented.

Friends And Related Function Documentation

friend class ::chesspp::util::JsonReader
friend

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