C++ Actor Framework 1.0.0
Loading...
Searching...
No Matches
caf::json_value Class Reference

Represents an immutable JSON value. More...

#include <json_value.hpp>

Public Member Functions

 json_value () noexcept
 Creates a null JSON value.
 
 json_value (const detail::json::value *val, detail::json::storage_ptr sptr) noexcept
 
 json_value (json_value &&) noexcept=default
 
 json_value (const json_value &) noexcept=default
 
json_valueoperator= (json_value &&) noexcept=default
 
json_valueoperator= (const json_value &) noexcept=default
 
bool is_null () const noexcept
 Checks whether the value is null.
 
bool is_undefined () const noexcept
 Checks whether the value is undefined.
 
bool is_integer () const noexcept
 Checks whether the value is an int64_t.
 
bool is_unsigned () const noexcept
 Checks whether the value is an uint64_t.
 
bool is_double () const noexcept
 Checks whether the value is a double.
 
bool is_number () const noexcept
 Checks whether the value is a number, i.e., an int64_t, a uint64_t or a double.
 
bool is_bool () const noexcept
 Checks whether the value is a bool.
 
bool is_string () const noexcept
 Checks whether the value is a JSON string (std::string_view).
 
bool is_array () const noexcept
 Checks whether the value is an JSON array.
 
bool is_object () const noexcept
 Checks whether the value is a JSON object.
 
int64_t to_integer (int64_t fallback=0) const
 Converts the value to an int64_t or returns fallback if the value is not a valid number.
 
uint64_t to_unsigned (uint64_t fallback=0) const
 Converts the value to an uint64_t or returns fallback if the value is not a valid number.
 
double to_double (double fallback=0.0) const
 Converts the value to a double or returns fallback if the value is not a valid number.
 
bool to_bool (bool fallback=false) const
 Converts the value to a bool or returns fallback if the value is not a valid boolean.
 
std::string_view to_string () const
 Returns the value as a JSON string or an empty string if the value is not a string.
 
std::string_view to_string (std::string_view fallback) const
 Returns the value as a JSON string or fallback if the value is not a string.
 
json_array to_array () const
 Returns the value as a JSON array or an empty array if the value is not an array.
 
json_array to_array (json_array fallback) const
 Returns the value as a JSON array or fallback if the value is not an array.
 
json_object to_object () const
 Returns the value as a JSON object or an empty object if the value is not an object.
 
json_object to_object (json_object fallback) const
 Returns the value as a JSON object or fallback if the value is not an object.
 
bool equal_to (const json_value &other) const noexcept
 Compares two JSON values for equality.
 
template<class Buffer >
void print_to (Buffer &buf, size_t indentation_factor=0) const
 Prints the JSON value to buf.
 

Static Public Member Functions

static json_value undefined () noexcept
 Creates an undefined JSON value.
 
static expected< json_valueparse (std::string_view str)
 Attempts to parse str as JSON input into a self-contained value.
 
static expected< json_valueparse_shallow (std::string_view str)
 Attempts to parse str as JSON input into a value that avoids copies where possible by pointing into str.
 
static expected< json_valueparse_in_situ (std::string &str)
 Attempts to parse str as JSON input.
 
static expected< json_valueparse_file (const char *path)
 Attempts to parse the content of the file at path as JSON input into a self-contained value.
 
static expected< json_valueparse_file (const std::string &path)
 Attempts to parse the content of the file at path as JSON input into a self-contained value.
 

Friends

template<class Inspector >
bool inspect (Inspector &inspector, json_value &val)
 Applies the Inspector to the JSON value val.
 

Related Symbols

(Note that these are not member symbols.)

CAF_CORE_EXPORT std::string to_string (const json_value &val)
 

Detailed Description

Represents an immutable JSON value.

Member Function Documentation

◆ is_undefined()

bool caf::json_value::is_undefined ( ) const
noexcept

Checks whether the value is undefined.

This special state indicates that a previous key lookup failed.

◆ parse_file()

expected< json_value > caf::json_value::parse_file ( const std::string & path)
static

Attempts to parse the content of the file at path as JSON input into a self-contained value.

◆ parse_in_situ()

expected< json_value > caf::json_value::parse_in_situ ( std::string & str)
static

Attempts to parse str as JSON input.

Decodes JSON in place and points back into the str for all strings in the JSON input.

Warning
The returned json_value may hold pointers into str. Thus, the input must outlive the json_value and any other JSON objects created from that value.

◆ parse_shallow()

expected< json_value > caf::json_value::parse_shallow ( std::string_view str)
static

Attempts to parse str as JSON input into a value that avoids copies where possible by pointing into str.

Warning
The returned json_value may hold pointers into str. Thus, the input must outlive the json_value and any other JSON objects created from that value.

◆ undefined()

json_value caf::json_value::undefined ( )
staticnoexcept

Creates an undefined JSON value.

This special state usually indicates that a previous key lookup failed.


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