json::value
| Type | Class |
| Namespace | conjure::core::json |
| Include File Path | engine/include/conjure/core/json/value.h |
| Source File Path | engine/src/core/json/value.cpp |
| API ↗ | JSON |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| private | constexpr value(
void *node,
const document *owner) noexcept; | |
| public | constexpr value() noexcept = default; | An invalid value: not part of any document, every accessor returns its fallback. |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mNode | void * | nullptr | |
| private | mOwner | const document * | nullptr |
Functions
Public
as_bool
as_bool[[nodiscard]] bool as_bool(
bool fallback = false) const noexcept;The boolean, or fallback when this is not a bool.
as_f32
as_f32Any number as f32 (rounded), or fallback when this is not a number or its magnitude exceeds the f32 range (the cast would be undefined behaviour).
as_f64
as_f64Any number as f64 (large integers round), or fallback when this is not a number.
as_i64
as_i64The number as i64. Integers outside the i64 range and non-integral reals yield fallback; integral reals convert.
as_string
as_string[[nodiscard]] std::string_view as_string(
std::string_view fallback = {}) const noexcept;The string bytes (UTF-8, may contain embedded zeros), or fallback when this is not a string. The view lives as long as the document.
as_u64
as_u64The number as u64. Negative values and non-integral reals yield fallback.
begin
begin[[nodiscard]] array_iterator begin() const noexcept;Iteration over array elements: for (value item : array). Empty for non-arrays.
contains
contains[[nodiscard]] bool contains(
std::string_view key) const noexcept;True when this is an object with a member named key.
end
end[[nodiscard]] array_iterator end() const noexcept;get
get[[nodiscard]] std::optional<value> get(
std::string_view key) const noexcept;The member named key, or nullopt when missing or not an object.
is_array
is_array[[nodiscard]] bool is_array() const noexcept;is_bool
is_bool[[nodiscard]] bool is_bool() const noexcept;is_integer
is_integer[[nodiscard]] bool is_integer() const noexcept;True for a number written without fraction or exponent (fits i64 or u64). 3.0 is a number but not an integer.
is_null
is_null[[nodiscard]] bool is_null() const noexcept;True for a JSON null and for an invalid value. Use is_valid() to tell them apart.
is_number
is_number[[nodiscard]] bool is_number() const noexcept;is_object
is_object[[nodiscard]] bool is_object() const noexcept;is_string
is_string[[nodiscard]] bool is_string() const noexcept;is_valid
is_valid[[nodiscard]] bool is_valid() const noexcept;False for a default-constructed value or the result of a failed lookup.
members
members[[nodiscard]] object_range members() const noexcept;Iteration over object members in document order. Empty for non-objects.
owner
owner[[nodiscard]] const document *owner() const noexcept;The document this view points into, or nullptr when invalid. Informational only; stale once the document has been moved.
size
size[[nodiscard]] usize size() const noexcept;Number of elements (array) or members (object); 0 for anything else.
to
totemplate <json_convertible T> [[nodiscard]] result<T> to() const;Converts through json_converter<T>; see that template for the error codes.
type
type[[nodiscard]] json_type type() const noexcept;The kind of this value. Invalid values report NULL_VALUE.
Operator Overloads
Public
operator==
operator==[[nodiscard]] bool operator==(
const value &other) const;Structural equality, defined as "same canonical text": objects compare regardless of member order (duplicate keys pair up in order); integers compare mathematically; reals compare bit for bit (so -0.0 differs from 0.0); an integer never equals a real. Two invalid values are equal; an invalid value never equals a valid one. Walks both trees with an explicit stack, so any nesting depth is safe. Objects with the same key sequence compare pairwise. When the keys are in a different order, matching uses a temporary index with at most one allocation and O(n log n) key comparisons for n members.
operator[]
operator[]Element index of an array, or an invalid value when out of range or not an array.
[[nodiscard]] value operator[](
std::string_view key) const noexcept;The first member named key of an object, or an invalid value when missing or not an object. Never asserts.