class
valueholds a json value such as <std::
Constructors, destructors, conversion operators
-
template <is_allowed_value_type val_type>value(const val_type& val) noexcept
- constructor for ljson::
value - value(const value& other)
- copy constructor for ljson::
value - value(const value&& other)
- move constructor for ljson::
value - value() noexcept
- constructor which sets an empty ljson::
value
Public functions
- auto as_boolean() → bool
- cast ljson::
value into a boolean if it is holding a json boolean (bool) - auto as_double() → double
- cast ljson::
value into a number if it is holding a json number (double) - auto as_integer() → int64_t
- cast ljson::
value into a number if it is holding a json number (int64_t) -
auto as_null() → null_
type - cast ljson::
value into a null if it is holding a json null (ljson:: null_type) - auto as_number() → double
- cast ljson::
value into a number if it is holding a json number (double or int64_t) -
auto as_string() → std::
string - cast ljson::
value into a string if it is holding a json string (std:: string) - auto is_boolean() const → bool noexcept
- checks if ljson::
value is holding json boolean (bool) - auto is_double() const → bool noexcept
- checks if ljson::
value is holding json number (double) - auto is_empty() const → bool noexcept
- checks if ljson::
value is not holding json value (ljson:: monostate) - auto is_integer() const → bool noexcept
- checks if ljson::
value is holding json number (int64_t) - auto is_null() const → bool noexcept
- checks if ljson::
value is holding json null (ljson:: null_type) - auto is_number() const → bool noexcept
- checks if ljson::
value is holding json number (double or int64_t) - auto is_string() const → bool noexcept
- checks if ljson::
value is holding json string (std:: string) - auto operator=(const value& other) → value&
- copy assignment for ljson::
value - auto operator=(const value&& other) → value&
- move assignment for ljson::
value -
template <is_allowed_value_type val_type>void set_value_type(const val_type& val) noexcept
- sets the value and type of ljson::
value -
auto set_value_type(const std::
string& val, value_type type) → expected<monostate, error> - sets the value and type of ljson::
value -
auto stringify() const → std::
string noexcept - cast the json value into a std::
string - auto try_as_boolean() → expected<bool, error> noexcept
- cast ljson::
value into a bool if it is holding a json boolean (bool) - auto try_as_double() → expected<double, error> noexcept
- cast ljson::
value into a double if it is holding a json number (double) - auto try_as_integer() → expected<int64_t, error> noexcept
- cast ljson::
value into a int64_t if it is holding a json number (int64_t) -
auto try_as_null() → expected<null_
type, error> noexcept - cast ljson::
value into a ljson:: null_type if it is holding a json null (ljson:: null_type) - auto try_as_number() → expected<double, error> noexcept
- cast ljson::
value into a double if it is holding a json number (double or int64_t) -
auto try_as_string() → expected<std::
string, error> noexcept - cast ljson::
value into a std:: string if it is holding a json string (std:: string) - auto type() const → ljson::value_type noexcept
- gets the type of the stored json value
-
auto type_name() const → std::
string noexcept - gets string representation of ljson::value_type of the internal value
Function documentation
template <is_allowed_value_type val_type>
ljson:: value:: value(const val_type& val) noexcept
constructor for ljson::
Parameters | |
---|---|
val | json value to be set |
ljson:: value:: value(const value& other)
copy constructor for ljson::
Parameters | |
---|---|
other | ljson:: |
ljson:: value:: value(const value&& other)
move constructor for ljson::
Parameters | |
---|---|
other | ljson:: |
bool ljson:: value:: as_boolean()
cast ljson::
Returns | json boolean |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold json boolean |
double ljson:: value:: as_double()
cast ljson::
Returns | json number |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold json number |
int64_t ljson:: value:: as_integer()
cast ljson::
Returns | json number |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold json number |
null_ type ljson:: value:: as_null()
cast ljson::
Returns | json null |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold json null |
double ljson:: value:: as_number()
cast ljson::
Returns | json number |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold json number |
std:: string ljson:: value:: as_string()
cast ljson::
Returns | json string |
---|---|
Exceptions | |
ljson:: |
if it doesn't json string |
bool ljson:: value:: is_boolean() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: value:: is_double() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: value:: is_empty() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: value:: is_integer() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: value:: is_null() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: value:: is_number() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: value:: is_string() const noexcept
checks if ljson::
Returns | true if it does |
---|
value& ljson:: value:: operator=(const value& other)
copy assignment for ljson::
Parameters | |
---|---|
other | ljson:: |
Returns | the address of the modified ljson:: |
value& ljson:: value:: operator=(const value&& other)
move assignment for ljson::
Parameters | |
---|---|
other | ljson:: |
Returns | the address of the modified ljson:: |
template <is_allowed_value_type val_type>
void ljson:: value:: set_value_type(const val_type& val) noexcept
sets the value and type of ljson::
Parameters | |
---|---|
val | json value to be set |
expected<monostate, error> ljson:: value:: set_value_type(const std:: string& val,
value_type type)
sets the value and type of ljson::
Parameters | |
---|---|
val | json value to be set |
type | json type (ljson::value_type) to be set |
Returns | ljson:: |
std:: string ljson:: value:: stringify() const noexcept
cast the json value into a std::
Returns | string representation of the value |
---|
expected<bool, error> ljson:: value:: try_as_boolean() noexcept
cast ljson::
Returns | bool or ljson:: |
---|
expected<double, error> ljson:: value:: try_as_double() noexcept
cast ljson::
Returns | double or ljson:: |
---|
expected<int64_t, error> ljson:: value:: try_as_integer() noexcept
cast ljson::
Returns | int64_t or ljson:: |
---|
expected<null_ type, error> ljson:: value:: try_as_null() noexcept
cast ljson::
Returns | ljson:: |
---|
expected<double, error> ljson:: value:: try_as_number() noexcept
cast ljson::
Returns | double or ljson:: |
---|
expected<std:: string, error> ljson:: value:: try_as_string() noexcept
cast ljson::
Returns | std:: |
---|
ljson::expected<std::string, error> string = value.try_as_string(); if (not string) { // handle error std::println("{}", string.error().message()); } else { // success std::string string_value = string.value(); }
std:: string ljson:: value:: type_name() const noexcept
gets string representation of ljson::value_type of the internal value
Returns | string name of the value_type |
---|