Skip to content

Engine → Core → value.h

json::value

Syntax

class CONJURE_API value

Constructors

AccessSignatureDescription
privateconstexpr value( void *node, const document *owner) noexcept;
publicconstexpr value() noexcept = default;An invalid value: not part of any document, every accessor returns its fallback.

Variables

AccessNameTypeDefaultDescription
privatemNodevoid *nullptr
privatemOwnerconst document *nullptr

Functions

Public

as_bool

[[nodiscard]] bool as_bool(
    bool fallback = false) const noexcept;

The boolean, or fallback when this is not a bool.

as_f32

[[nodiscard]] f32 as_f32(
    f32 fallback = 0.0f) const noexcept;

Any 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

[[nodiscard]] f64 as_f64(
    f64 fallback = 0.0) const noexcept;

Any number as f64 (large integers round), or fallback when this is not a number.

as_i64

[[nodiscard]] i64 as_i64(
    i64 fallback = 0) const noexcept;

The number as i64. Integers outside the i64 range and non-integral reals yield fallback; integral reals convert.

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

[[nodiscard]] u64 as_u64(
    u64 fallback = 0) const noexcept;

The number as u64. Negative values and non-integral reals yield fallback.

begin

[[nodiscard]] array_iterator begin() const noexcept;

Iteration over array elements: for (value item : array). Empty for non-arrays.

contains

[[nodiscard]] bool contains(
    std::string_view key) const noexcept;

True when this is an object with a member named key.

end

[[nodiscard]] array_iterator end() const noexcept;

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

[[nodiscard]] bool is_array() const noexcept;

is_bool

[[nodiscard]] bool is_bool() const noexcept;

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

[[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

[[nodiscard]] bool is_number() const noexcept;

is_object

[[nodiscard]] bool is_object() const noexcept;

is_string

[[nodiscard]] bool is_string() const noexcept;

is_valid

[[nodiscard]] bool is_valid() const noexcept;

False for a default-constructed value or the result of a failed lookup.

members

[[nodiscard]] object_range members() const noexcept;

Iteration over object members in document order. Empty for non-objects.

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

[[nodiscard]] usize size() const noexcept;

Number of elements (array) or members (object); 0 for anything else.

to

template <json_convertible T> [[nodiscard]] result<T> to() const;

Converts through json_converter<T>; see that template for the error codes.

type

[[nodiscard]] json_type type() const noexcept;

The kind of this value. Invalid values report NULL_VALUE.

Operator Overloads

Public

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[]

[[nodiscard]] value operator[](
    usize index) const noexcept;

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.