C++ Actor Framework 0.19
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
caf::json_value Class Reference

Represents an immutable JSON value. More...

#include <json_value.hpp>

Public Member Functions

 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_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 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
 
double to_double (double fallback=0.0) const
 
bool to_bool (bool fallback=false) const
 
std::string_view to_string () const
 
std::string_view to_string (std::string_view fallback) const
 
json_array to_array () const
 
json_array to_array (json_array fallback) const
 
json_object to_object () const
 
json_object to_object (json_object fallback) const
 
bool equal_to (const json_value &other) const noexcept
 
template<class Buffer >
void print_to (Buffer &buf, size_t indentation_factor=0) const
 

Static Public Member Functions

static json_value undefined () noexcept
 
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)
 

Related Functions

(Note that these are not member functions.)

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()

static 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()

static 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()

static 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.

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