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
-
std::expected<const field*, error> operator[](std::string_view name) const noexcept#
Query a map’s direct children with subscript operator syntax.
- Parameters:
name – The field name to search for
- Returns:
Constant pointer to a field if found, an error otherwise
-
std::string json() const noexcept#
Get the map as JSON.
- Returns:
A JSON string representation of the map
-
map &clobber(field &f) noexcept#
Warning
doxygenvariable: Cannot find variable “god::value_t” in doxygen xml output for project “libgod” from directory: doxygen/xml
-
class value#
Convenience wrapper for any of the valid internal value types.
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
-
std::string json() const noexcept#
Get the value as JSON.
- Returns:
A JSON string representation of the value
-
bool operator==(const value &other) const = default#
-
class field#
Represents a God field, consisting of an identifier and an opaque value object
Constructors
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 bool operator!=(const field &other) const noexcept#
Boolean comparison inequality operator.
- Parameters:
other – Another field to compare against
- Returns:
true if they are not equal, false if they are
-
bool operator!() const noexcept#
Boolean self operator.
- Returns:
True if the field has a non-empty identifier, false otherwise
-
bool operator&&(const field &other) const noexcept#
Boolean AND operator.
- Parameters:
other – Another field
- Returns:
true if both have non-empty identifiers, false otherwise
-
bool operator||(const field &other) const noexcept#
Boolean OR operator.
- Parameters:
other – Another field
- Returns:
true if at least one of them have non-empty identifiers, 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.
-
std::string json() const noexcept#
Get the field as JSON.
- Returns:
A JSON string representation of the field
-
inline bool operator==(const field &other) const#
-
class document#
The top-level data structure of the God format.
Constructors
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.
-
bool operator!() const noexcept#
Boolean operator overload.
- Returns:
true if the document has fields, false if it has no fields.
-
bool operator||(const document &other) const noexcept#
Boolean OR operator overload.
- Parameters:
other – Another document for boolean OR evaluation
- Returns:
true if either of the documents are non-empty, false otherwise
-
bool operator&&(const document &other) const noexcept#
Boolean AND operator overload.
- Parameters:
other – Another document for boolean AND evaluation
- Returns:
true if both of the documents are non-empty, 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.
-
bool operator==(const document &other) const = default#