TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::JsonValue Class Reference

A JSON value (RFC 8259): null, bool, number, string, array or object. More...

#include <gui_core/gui_json.h>

Public Types

using Array = std::vector<JsonValue>
using Object = std::vector<std::pair<std::string, JsonValue>>
 members in order

Public Member Functions

 JsonValue ()=default
 Default is null.
 JsonValue (std::nullptr_t)
 JsonValue (bool value)
 JsonValue (int value)
 JsonValue (double value)
 JsonValue (std::string value)
 JsonValue (std::string_view value)
 JsonValue (const char *value)
 JsonValue (Array value)
 JsonValue (Object value)
std::string Write () const
 Compact JSON text (no whitespace); NaN and infinity are written as null.
const JsonValue * Find (std::string_view key) const
 An object's member by name, or null when absent (or not an object).

Static Public Member Functions

static Result< JsonValue > Parse (std::string_view text)
 Parses JSON Text. Nesting deeper than 64 is an error, not a stack overflow.
bool IsNull () const
 True when the value is of that type.
bool IsBool () const
 True when the value is of that type.
bool IsNumber () const
 True when the value is of that type.
bool IsString () const
 True when the value is of that type.
bool IsArray () const
 True when the value is of that type.
bool IsObject () const
 True when the value is of that type.
bool AsBool (bool fallback=false) const
 The value, or fallback when it is of another type.
double AsNumber (double fallback=0.0) const
 The value, or fallback when it is of another type.
const std::string & AsString () const
 The string, array items or object members; empty when the value is of another type.
const Array & Items () const
 The string, array items or object members; empty when the value is of another type.
const Object & Members () const
 The string, array items or object members; empty when the value is of another type.
JsonValue & Set (std::string_view key, JsonValue value)
 Set adds or replaces an object's member, Push appends to an array.
JsonValue & Push (JsonValue value)
 Set adds or replaces an object's member, Push appends to an array.
static JsonValue MakeArray ()
 An empty array / object, to fill with Push / Set.
static JsonValue MakeObject ()
 An empty array / object, to fill with Push / Set.

Detailed Description

A JSON value (RFC 8259): null, bool, number, string, array or object.

Objects keep their members in order, so what is written reads back the same.

Member Typedef Documentation

◆ Array

using tachyon::JsonValue::Array = std::vector<JsonValue>

◆ Object

using tachyon::JsonValue::Object = std::vector<std::pair<std::string, JsonValue>>

members in order

Member Function Documentation

◆ MakeArray()

JsonValue tachyon::JsonValue::MakeArray ( )
inlinestatic

An empty array / object, to fill with Push / Set.

◆ MakeObject()

JsonValue tachyon::JsonValue::MakeObject ( )
inlinestatic

An empty array / object, to fill with Push / Set.

◆ Parse()

Result< JsonValue > tachyon::JsonValue::Parse ( std::string_view text)
static

Parses JSON Text. Nesting deeper than 64 is an error, not a stack overflow.

◆ Write()

std::string tachyon::JsonValue::Write ( ) const

Compact JSON text (no whitespace); NaN and infinity are written as null.

◆ IsNull()

bool tachyon::JsonValue::IsNull ( ) const
inline

True when the value is of that type.

◆ IsBool()

bool tachyon::JsonValue::IsBool ( ) const
inline

True when the value is of that type.

◆ IsNumber()

bool tachyon::JsonValue::IsNumber ( ) const
inline

True when the value is of that type.

◆ IsString()

bool tachyon::JsonValue::IsString ( ) const
inline

True when the value is of that type.

◆ IsArray()

bool tachyon::JsonValue::IsArray ( ) const
inline

True when the value is of that type.

◆ IsObject()

bool tachyon::JsonValue::IsObject ( ) const
inline

True when the value is of that type.

◆ AsBool()

bool tachyon::JsonValue::AsBool ( bool fallback = false) const
inline

The value, or fallback when it is of another type.

◆ AsNumber()

double tachyon::JsonValue::AsNumber ( double fallback = 0.0) const
inline

The value, or fallback when it is of another type.

◆ AsString()

const std::string & tachyon::JsonValue::AsString ( ) const

The string, array items or object members; empty when the value is of another type.

◆ Items()

const Array & tachyon::JsonValue::Items ( ) const

The string, array items or object members; empty when the value is of another type.

◆ Members()

const Object & tachyon::JsonValue::Members ( ) const

The string, array items or object members; empty when the value is of another type.

◆ Find()

const JsonValue * tachyon::JsonValue::Find ( std::string_view key) const

An object's member by name, or null when absent (or not an object).

◆ Set()

JsonValue & tachyon::JsonValue::Set ( std::string_view key,
JsonValue value )

Set adds or replaces an object's member, Push appends to an array.

A value of another type is replaced by an empty object / array first. Both return the stored value.

◆ Push()

JsonValue & tachyon::JsonValue::Push ( JsonValue value)

Set adds or replaces an object's member, Push appends to an array.

A value of another type is replaced by an empty object / array first. Both return the stored value.


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