std1.0.0-beta-7 SafeC docs

std :: serial::value

Struct std::Value

#include <std/serial/value.h> source

struct Value {
    int kind;
    long long int_val;
    double float_val;
    int bool_val;
    ?&heap char str_val;
    struct Vec<struct Value> arr_val;
    struct Vec<struct ObjectEntry> obj_val;
}

Fields

§int kindsource

one of the VAL_* constants above

§long long int_valsource

VAL_INT

§double float_valsource

VAL_FLOAT

§int bool_valsource

VAL_BOOL

§?&heap char str_valsource

VAL_STRING — heap-allocated, NUL-terminated, owned;

§struct Vec<struct Value> arr_valsource

empty (null) for every other 'kind'

VAL_ARRAY — elements by value

§struct Vec<struct ObjectEntry> obj_valsource

VAL_OBJECT — key/value entries by value

Methods

§static struct Value null()source · definition
§static struct Value from_bool(int v)source · definition
§static struct Value from_int(long long v)source · definition
§static struct Value from_float(double v)source · definition
§static struct Value from_str(const &char s)source · definition

copies s

§static struct Value array()source · definition

empty; grow with v.array_push

§static struct Value object()source · definition

empty; grow with v.object_set

§int kind_of() constsource · definition
§int is_null() constsource · definition
§int as_bool() constsource · definition
§long long as_int() constsource · definition
§double as_float() constsource · definition
§const &char as_string() constsource · definition
§unsigned long array_len() constsource · definition

Array/Object element access (read-only views — the returned reference aliases storage owned by this Value, don't free it separately). 'array_at' trusts 'idx' is in range (see array_len()); 'object_get' is the one nullable lookup — no entry for 'key' is a real, expected outcome, not a caller error.

§&Value array_at(unsigned long idx) constsource · definition
§unsigned long object_len() constsource · definition
§const &char object_key_at(unsigned long idx) constsource · definition

The idx-th entry of an object, in insertion order (for iterating a VAL_OBJECT's keys — e.g. a YAML/JSON map whose order matters): its key ("" if the entry's key allocation failed) and its value. Like array_at, both trust 'idx' < object_len().

§&Value object_value_at(unsigned long idx) constsource · definition
§?&Value object_get(const &char key) constsource · definition

Empty (null case) if the key isn't present.

§void array_push(struct Value v)source · definition

Array/Object building. Both take ownership of 'v' (see the file-level ownership note above).

§void object_set(const &char key, struct Value v)source · definition
§struct Value clone() constsource · definition

Deep copy / recursive release of the whole tree.

§void drop()source · definition
§void free() consumesource · definition

= drop()

§generic<F: Format> struct String encode(F f) constsource · definition

A fresh String holding this tree in format f.

§generic<F: Format> static struct Value decode(F f, const &char text, ?&int ok)source · definition

Parses text in format f; *ok (if non-null) is 1 on success, else 0.