Types#

Note

Declared in <god/types.hpp>

class list : public std::vector<value>#

Represents a God list, consisting of elements (god::values).

class map : public std::vector::vector#

Represents a God map, consisting of fields

Methods

map &clobber(field &f) noexcept#

Add a field to the map, overwriting any existing field of the same name.

Parameters:

f – A reference to a field

Returns:

A reference to the map; chainable

std::expected<int, error> add(field &f) noexcept#

Add a field to the map, without overwriting.

Parameters:

f – A reference to a field

Returns:

0 when successful or an error

Warning

doxygenvariable: Cannot find variable “god::value_t” in doxygen xml output for project “libgod” from directory: doxygen/xml

class value#

An convenience wrapper for any of the valid internal value types

Constructors

template<typename T>
inline value(T &&v)#

Main constructor for the value class.

Methods

bool operator==(const value &other) const = default#

Boolean comparison operator.

Parameters:

other – Another value to compare

Returns:

true if they are identical

template<typename T>
inline T &as()#

Get an underlying value.

Returns:

A mutable reference to the value as type T

template<typename T>
inline const T &as() const#

Get an underlying value.

Returns:

A constant reference to the value as type T

template<typename T>
inline bool is() const#

Verify the underlying type of a value.

Returns:

True if the underlying value is of type T, false otherwise

class field#

Represents a God field, consisting of an identifier and an opaque value object

Members

std::string name#

The fields’ identifier.

value val#

The fields’ opaque value.

Constructors

inline field(std::string pname, value v)#

Main constructor for the field class.

Parameters:
  • pname – The identifier

  • v – The value object

Methods

inline bool operator==(const field &other) const#

Boolean comparison operator.

Parameters:

other – Another field to compare

Returns:

True if the fields names/values are identical, false otherwise

inline field &identifier(std::string pname) noexcept#

Set the field’s identifier.

Parameters:

pname – The new identifier string

Returns:

A reference to the field; chainable.

class document#

The top-level data structure of the God format.

Members

std::vector<field> fields#

The fields contained within the document.

Methods

bool operator==(const document &other) const = default#

Boolean comparison operator.

Parameters:

other – Another document to compare.

Returns:

true when they are identical, false otherwise.

void load(const std::string &inputfile)#

Populate a document by parsing an input file.

Parameters:

inputfile – A path to the file to read

void load(std::istream &is)#

Populate a document by parsing input from a stream.

Parameters:

is – The input stream to read from

std::string json() const noexcept#

Get the document in JSON string representation.

Returns:

The resulting string in JSON format

std::expected<const value*, error> lookup(std::string_view qry) const noexcept#

Search for a field using path syntax as a specific type.

Parameters:

qry – The period separated path to search for

Returns:

A constant pointer to an value or an error

std::string string() const noexcept#

Get the document in canonical string representation.

Returns:

The resulting string

template<typename t>
inline std::expected<t, error> query(std::string_view path)#

Search for a field using path syntax as a specific type.

Parameters:

path – The period separated path to search for

Returns:

A constant pointer to an underlying value (of type t) or an error

std::expected<const value*, error> operator[](std::string_view name) const noexcept#

Search for a field using array subscript syntax.

Parameters:

name – The field name to search for

Returns:

A constant pointer to a value or an error

document &clobber(god::field &f) noexcept#

Append a field to the document, or replace an existing field if they have the same identifier.

Parameters:

f – A reference to a field

Returns:

A reference to the document; chainable

std::expected<int, error> add(god::field &f) noexcept#

Append a field to the document without overwriting.

Parameters:

f – A reference to a field

Returns:

0 when successful, or an error if a field with the same identifier already exists.