Skip to content

Engine → Core → writer.h

json::writer

Syntax

class CONJURE_API writer

Constructors

AccessSignatureDescription
publicwriter();
publicwriter( const writer &) = default;
publicwriter( writer &&) noexcept = default;

Destructors

AccessSignatureDescription
public~writer();

Variables

AccessNameTypeDefaultDescription
privatemBufferstd::string{}
privatemRootWrittenboolfalse
privatemStackstd::vector<frame>{}

Functions

Public

begin_array

void begin_array();

Opens an array as the root, an array element or the value of the pending key.

begin_object

void begin_object();

Opens an object as the root, an array element or the value of the pending key.

depth

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

Number of open containers.

end_array

void end_array();

Closes the innermost array. Asserts when the innermost scope is not an array.

end_object

void end_object();

Closes the innermost object. Asserts when the innermost scope is not an object or a key is pending.

finish

[[nodiscard]] std::string finish();

Returns the text and resets the writer. Asserts when containers are still open or no root was written (the partial text is still returned).

is_complete

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

True when exactly one root value has been written and every container is closed.

key

void key(
    std::string_view name);

Writes a member key. Asserts outside an object or when a key is already pending.

reset

void reset();

Discards everything written so far.

text

[[nodiscard]] std::string_view text() const noexcept;

The text written so far (possibly incomplete).

value

void value(
    bool item);

Writes a scalar as the root, an array element or the value of the pending key. Non-finite reals assert and are written as null; a null C string writes null, as in the document API. Strings must be valid UTF-8 (asserted in Debug, written as-is otherwise). Integral types without an overload of their own widen to i64 or u64.

void value(
    i32 item);
void value(
    u32 item);
void value(
    i64 item);
void value(
    u64 item);
void value(
    f32 item);
void value(
    f64 item);
void value(
    std::string_view item);
void value(
    const char *item);
void value(
    std::nullptr_t);
template <std::integral T> requires (!std::same_as<T, bool> && !std::same_as<T, i32> && !std::same_as<T, u32> && !std::same_as<T, i64> && !std::same_as<T, u64>) void value(
    T item);

write_raw_json

void write_raw_json(
    std::string_view rawJson);

Inserts pre-serialised JSON verbatim where a value is expected. Debug builds parse the text and assert when it is not a single valid JSON value.

Private

append_string

void append_string(
    std::string_view text);

begin_value

[[nodiscard]] bool begin_value();

Operator Overloads

Public

operator=

writer &operator=(
    const writer &) = default;
writer &operator=(
    writer &&) noexcept = default;