gko::config::pnode#

Property-tree node — the in-memory representation of a parsed configuration document. Each node is either a scalar (string, integer, real, boolean), an array of nodes, or a map from string keys to nodes, mirroring the structure of JSON.

pnode is what the gko::config::parse entry point consumes; the expectation is that the application parses its JSON / YAML / TOML config with whatever library it prefers and converts the result into a pnode tree.

class pnode#

pnode describes a tree of properties.

A pnode can either be empty, hold a value (a string, integer, real, or bool), contain an array of pnode., or contain a mapping between strings and pnodes.

Public Types

enum class tag_t#

tag_t is the indicator for the current node storage.

Values:

enumerator empty#
enumerator array#
enumerator boolean#
enumerator real#
enumerator integer#
enumerator string#
enumerator map#

Public Functions

explicit pnode()#

Default constructor: create an empty node

explicit pnode(bool boolean)#

Constructor for bool

Parameters:

boolean – the bool type value

template<typename T, std::enable_if_t<std::is_integral<T>::value>* = nullptr>
explicit pnode(
T integer,
)#

Constructor for integer with all integer type

Template Parameters:

T – input type

Parameters:

integer – the integer type value

explicit pnode(const std::string &str)#

Constructor for string

Parameters:

str – string type value

explicit pnode(const char *str)#

Constructor for char* (otherwise, it will use bool)

Parameters:

str – the string like “…”

explicit pnode(double real)#

Constructor for double (and also float)

Parameters:

real – the floating point type value

explicit pnode(const array_type &array)#

Constructor for array

Parameters:

array – an pnode array

explicit pnode(const map_type &map)#

Constructor for map

Parameters:

map – a (string, pnode)-map

explicit operator bool() const noexcept#

bool conversion. It’s true if and only if it is not empty.

bool operator==(const pnode &rhs) const#

Check whether the representing data of two pnodes are the same

bool operator!=(const pnode &rhs) const#

Check whether the representing data of two pnodes are different.

tag_t get_tag() const#

Get the current node tag.

Returns:

the tag

const array_type &get_array() const#

Access the array stored in this property node. Throws gko::InvalidStateError if the property node does not store an array.

Returns:

the array

const map_type &get_map() const#

Access the map stored in this property node. Throws gko::InvalidStateError if the property node does not store a map.

Returns:

the map

bool get_boolean() const#

Access the boolean value stored in this property node. Throws gko::InvalidStateError if the property node does not store a boolean value.

Returns:

the boolean value

std::int64_t get_integer() const#

  • Access the integer value stored in this property node. Throws gko::InvalidStateError if the property node does not store an integer value.

Returns:

the integer value

double get_real() const#

Access the real floating point value stored in this property node. Throws gko::InvalidStateError if the property node does not store a real value

Returns:

the real floating point value

const std::string &get_string() const#

Access the string stored in this property node. Throws gko::InvalidStateError if the property node does not store a string.

Returns:

the string

const pnode &get(const std::string &key) const#

This function is to access the data under the map. It will throw error when it does not hold a map. When access non-existent key in the map, it will return an empty node.

Parameters:

key – the key for the node of the map

Returns:

node. If the map does not have the key, return an empty node.

const pnode &get(int index) const#

This function is to access the data under the array. It will throw error when it does not hold an array or access out-of-bound index.

Parameters:

index – the node index in array

Returns:

node.