JWTXX
C++ library for JWT
Loading...
Searching...
No Matches
JWTXX::Value Class Reference

Represents a JSON value that can hold any JSON type. More...

#include <value.h>

Classes

class  Error
 Value-specific exception. More...
 
struct  Null
 Represents a JSON null value. More...
 

Public Types

using Array = std::vector<Value>
 Represents a JSON array (vector of Values).
 
using Object = std::unordered_map<std::string, Value>
 Represents a JSON object (string to Value map).
 

Public Member Functions

 Value () noexcept
 Default constructor. Creates a null value.
 
 Value (bool v) noexcept
 Boolean constructor.
 
 Value (int64_t v) noexcept
 Integer constructor.
 
 Value (const char *v) noexcept
 C-string constructor.
 
 Value (std::string v) noexcept
 String constructor.
 
 Value (std::initializer_list< Array::value_type > vs) noexcept
 Array initializer list constructor.
 
 Value (Array v) noexcept
 Array constructor.
 
 Value (std::initializer_list< Object::value_type > vs) noexcept
 Object initializer list constructor.
 
 Value (Object v) noexcept
 Object constructor.
 
 Value (const Value &)=default
 Copy constructor.
 
 Value (Value &&)=default
 Move constructor.
 
Valueoperator= (const Value &)=default
 Copy assignment operator.
 
Valueoperator= (Value &&)=default
 Move assignment operator.
 
 ~Value ()=default
 Destructor.
 
bool isNull () const noexcept
 Checks if the value is null.
 
bool isBool () const noexcept
 Checks if the value is a boolean.
 
bool isInteger () const noexcept
 Checks if the value is an integer.
 
bool isString () const noexcept
 Checks if the value is a string.
 
bool isArray () const noexcept
 Checks if the value is an array.
 
bool isObject () const noexcept
 Checks if the value is an object.
 
bool getBool () const
 Gets the boolean value.
 
int64_t getInteger () const
 Gets the integer value.
 
std::string getString () const
 Gets the string value.
 
Array getArray () const
 Gets the array value.
 
Object getObject () const
 Gets the object value.
 
std::string toString () const
 Converts the value to its JSON string representation.
 
template<typename F>
auto visit (F &&f) const
 Applies a visitor function to the value.
 

Static Public Member Functions

static Value number (double v) noexcept
 Creates a floating point number Value.
 

Detailed Description

Represents a JSON value that can hold any JSON type.

Value can hold null, boolean, integer, floating point number, string, array, or object. Provides type-safe access with runtime type checking.

Constructor & Destructor Documentation

◆ Value() [1/8]

JWTXX::Value::Value ( bool v)
inlineexplicitnoexcept

Boolean constructor.

Parameters
vboolean value.

◆ Value() [2/8]

JWTXX::Value::Value ( int64_t v)
inlineexplicitnoexcept

Integer constructor.

Parameters
v64-bit integer value.

◆ Value() [3/8]

JWTXX::Value::Value ( const char * v)
inlineexplicitnoexcept

C-string constructor.

Parameters
vnull-terminated C string.

◆ Value() [4/8]

JWTXX::Value::Value ( std::string v)
inlineexplicitnoexcept

String constructor.

Parameters
vstring value.

◆ Value() [5/8]

JWTXX::Value::Value ( std::initializer_list< Array::value_type > vs)
inlineexplicitnoexcept

Array initializer list constructor.

Parameters
vsinitializer list of array elements.

◆ Value() [6/8]

JWTXX::Value::Value ( Array v)
inlineexplicitnoexcept

Array constructor.

Parameters
varray value.

◆ Value() [7/8]

JWTXX::Value::Value ( std::initializer_list< Object::value_type > vs)
inlineexplicitnoexcept

Object initializer list constructor.

Parameters
vsinitializer list of object key-value pairs.

◆ Value() [8/8]

JWTXX::Value::Value ( Object v)
inlineexplicitnoexcept

Object constructor.

Parameters
vobject value.

Member Function Documentation

◆ getArray()

Array JWTXX::Value::getArray ( ) const
inline

Gets the array value.

Returns
the array value.
Exceptions
Errorif the value is not an array.

◆ getBool()

bool JWTXX::Value::getBool ( ) const
inline

Gets the boolean value.

Returns
the boolean value.
Exceptions
Errorif the value is not a boolean.

◆ getInteger()

int64_t JWTXX::Value::getInteger ( ) const
inline

Gets the integer value.

Returns
the 64-bit integer value.
Exceptions
Errorif the value is not an integer.

◆ getObject()

Object JWTXX::Value::getObject ( ) const
inline

Gets the object value.

Returns
the object value.
Exceptions
Errorif the value is not an object.

◆ getString()

std::string JWTXX::Value::getString ( ) const
inline

Gets the string value.

Returns
the string value.
Exceptions
Errorif the value is not a string.

◆ isArray()

bool JWTXX::Value::isArray ( ) const
inlinenoexcept

Checks if the value is an array.

Returns
true if the value is an array, false otherwise.

◆ isBool()

bool JWTXX::Value::isBool ( ) const
inlinenoexcept

Checks if the value is a boolean.

Returns
true if the value is a boolean, false otherwise.

◆ isInteger()

bool JWTXX::Value::isInteger ( ) const
inlinenoexcept

Checks if the value is an integer.

Returns
true if the value is an integer, false otherwise.

◆ isNull()

bool JWTXX::Value::isNull ( ) const
inlinenoexcept

Checks if the value is null.

Returns
true if the value is null, false otherwise.

◆ isObject()

bool JWTXX::Value::isObject ( ) const
inlinenoexcept

Checks if the value is an object.

Returns
true if the value is an object, false otherwise.

◆ isString()

bool JWTXX::Value::isString ( ) const
inlinenoexcept

Checks if the value is a string.

Returns
true if the value is a string, false otherwise.

◆ number()

static Value JWTXX::Value::number ( double v)
inlinestaticnoexcept

Creates a floating point number Value.

Parameters
vdouble-precision floating point value.
Returns
Value containing the floating point number.
Note
Use this static method to create floating point values.

◆ toString()

std::string JWTXX::Value::toString ( ) const
inline

Converts the value to its JSON string representation.

Returns
JSON string representation of the value.
Note
Strings are returned with surrounding quotes, objects with braces, arrays with brackets.

◆ visit()

template<typename F>
auto JWTXX::Value::visit ( F && f) const
inline

Applies a visitor function to the value.

Template Parameters
Fvisitor function type.
Parameters
fvisitor function to apply.
Returns
result of applying the visitor.

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