Contents

class

SushiAI::Config::Value

One node of a parsed configuration document.

Declared in
include/SushiAI/config/value.hpp

Public member functions

Value()=default

Constructs the null value.

Kind kind() const noexcept

What this node holds.

bool is_null() const noexcept

Whether this node is JSON null.

bool as_bool(std::string_view context) const

Reads this value as a boolean.

Parameters

context

What this value is, for the diagnostic, e.g. "layer 3 'use_bias'".

Returns

The boolean.

Exceptions

Error

If this is not a boolean; names context and the kind found.

std::int64_t as_int(std::string_view context) const

Reads this value as a whole number.

Parameters

context

What this value is, for the diagnostic.

Returns

The number.

Exceptions

Error

If this is not a whole number; names context and the kind found.

double as_real(std::string_view context) const

Reads this value as a real number, widening integers.

Parameters

context

Context string for error diagnostics.

Returns

Floating-point numeric value.

Exceptions

Error

If value is neither real nor integer.

const std::string & as_string(std::string_view context) const

Reads this value as a string.

Parameters

context

What this value is, for the diagnostic.

Returns

The string.

Exceptions

Error

If this is not a string; names context and the kind found.

const std::vector< Value > & as_array(std::string_view context) const

Reads this value as an array.

Parameters

context

What this value is, for the diagnostic.

Returns

Its entries.

Exceptions

Error

If this is not an array; names context and the kind found.

bool has(std::string_view key) const noexcept

Whether this object holds key; false for any non-object.

Parameters

key

The key to look for.

Returns

True when this is an object carrying key.

const Value & at(std::string_view key, std::string_view context) const

Accesses child value associated with key.

Parameters

key

Property key to look up.

context

Context string for error diagnostics.

Returns

Const reference to value mapped to key.

Exceptions

Error

If node is not an object or key is absent.

const Value & at_or(std::string_view key, const Value &fallback) const noexcept

This object's value for key, or fallback when absent.

Parameters

key

The key to look up.

fallback

Returned when key is absent; must outlive the result.

Returns

The value, or fallback.

const std::vector< std::string > & keys() const noexcept

This object's keys, in the order the file spelled them.

void reject_unknown_keys(std::string_view context, SushiRuntime::span< const std::string_view > allowed) const

Rejects any key of this object absent from allowed.

Parameters

context

Context string for error diagnostics.

allowed

Permitted property key names.

Exceptions

Error

If an unrecognized key is present.

Value without(std::string_view key) const

Returns a copy of this object with key removed.

Parameters

key

Property key to omit.

Returns

New value copy omitting specified key.

Static public member functions

static Value boolean(bool value)

Builds a boolean.

Parameters

value

Its value.

Returns

The node.

static Value integer(std::int64_t value)

Builds a whole number.

Parameters

value

Its value.

Returns

The node.

static Value real(double value)

Builds a real.

Parameters

value

Its value.

Returns

The node.

static Value string(std::string value)

Builds a string.

Parameters

value

Its value; moved in.

Returns

The node.

static Value array(std::vector< Value > entries)

Builds an array.

Parameters

entries

Its entries; moved in.

Returns

The node.

static Value object(std::vector< std::string > keys, std::vector< Value > values)

Builds an object.

Parameters

keys

Its keys, in file order; moved in.

values

Its values, positionally matching keys; moved in.

Returns

The node.

Exceptions

Error

If the two vectors are of different lengths.