Clingo
|
This class provides a hierarchical configuration interface for clingo. More...
#include <config.hh>
Classes | |
class | Entry |
A configuration entry interface to interact with configuration entries. More... | |
Public Types | |
enum class | ValueFlags : uint8_t { none = 0 , get = 1 , set = 2 } |
The available value types of configuration entries. More... | |
using | KeyType = Clasp::Cli::ClaspCliConfig::KeyType |
The type of configuration keys to refer to entries. | |
using | IndexType = KeyType |
Type used for array indexing of configuration entries. | |
Public Member Functions | |
CLINGO_ENABLE_BITSET_ENUM (ValueFlags, friend) | |
Enabes bitset operations for ValueFlags. | |
ClingoConfig (Clasp::Cli::ClaspCliConfig &config) | |
Constructor for ClingoConfig. | |
void | key_info (KeyType key, int *n_children, int *array_info, ValueFlags *value_info) const |
Retrieves information about the specified key. | |
auto | description (KeyType key) const -> std::string_view |
Get the description of a configuration entry. | |
auto | array_at (KeyType key, KeyType index) const -> KeyType |
Get the key for an element at a specific index in an array entry. | |
auto | map_at (KeyType key, std::string_view path) const -> std::optional< KeyType > |
Get the key for a named subkey in a map entry. | |
auto | map_nth (KeyType key, KeyType index) const -> std::string_view |
Get the name of the nth subkey in a map entry. | |
auto | get_value (KeyType key) const -> std::optional< std::string_view > |
Get the value of a configuration entry. | |
void | set_value (KeyType key, std::string_view value) |
Set the value of a configuration entry. | |
void | add_entry (KeyType key, std::string_view name, std::string_view description, std::unique_ptr< Entry > entry=nullptr) |
Adds a new clingo configuration entry to the configuration tree. | |
void | str (Util::OutputBuffer &out, KeyType key) const |
Get the string representation of a configuration tree. | |
auto | clasp () const -> Clasp::Cli::ClaspCliConfig & |
Get the underlying clasp configuration object. | |
Static Public Member Functions | |
static auto | key_root () -> KeyType |
The root key of the configuration. | |
This class provides a hierarchical configuration interface for clingo.
It wraps a ClaspCliConfig object and allows managing configuration entries as a tree of keys, supporting both map and array entries. The class provides methods to query, retrieve, and set configuration values, as well as to add custom entries. Keys are encoded to distinguish between clingo and clasp entries, and array/map navigation is supported via dedicated methods.
Each instance should be used from a single thread. Methods throw on invalid operations or errors.
using CppClingo::Control::ClingoConfig::KeyType = Clasp::Cli::ClaspCliConfig::KeyType |
The type of configuration keys to refer to entries.
Each configuration key is represented as unsigned integer.
|
strong |
|
inline |
Constructor for ClingoConfig.
config | a reference to the Clasp CLI configuration object |
void CppClingo::Control::ClingoConfig::add_entry | ( | KeyType | key, |
std::string_view | name, | ||
std::string_view | description, | ||
std::unique_ptr< Entry > | entry = nullptr |
||
) |
Adds a new clingo configuration entry to the configuration tree.
Validates the key name format and inserts the key as a child of the given parent key. The key name may include an optional index in the form "key[index]" to add an array key. The index of such a key is used as default index when the key is accessed without an index.
If an updater is provided, it will be associated with the key to handle changes to the key's value.
key | parent clingo key under which the new key is added |
name | name of the key |
description | description string for the key |
entry | optional entry to handle arrays and values |
Get the key for an element at a specific index in an array entry.
Returns the key corresponding to the element at the given index in the array configuration entry specified by key
. Throws if the entry is not an array or the index is invalid.
key | key of the array entry |
index | index of the array element |
auto CppClingo::Control::ClingoConfig::description | ( | KeyType | key | ) | const -> std::string_view |
Get the description of a configuration entry.
key | key of the configuration entry |
auto CppClingo::Control::ClingoConfig::get_value | ( | KeyType | key | ) | const -> std::optional< std::string_view > |
Get the value of a configuration entry.
Returns the value associated with the given configuration key or std::nullopt if the value is not set. Throws if the key cannot have a value.
key | key of the configuration entry |
void CppClingo::Control::ClingoConfig::key_info | ( | KeyType | key, |
int * | n_children, | ||
int * | array_info, | ||
ValueFlags * | value_info | ||
) | const |
Retrieves information about the specified key.
key | a handle to a key |
n_children | the number of subkeys for this key |
array_info | the length of array keys or -1 for non-array keys |
value_info | whether the key has a value, can be read, and can be set |
auto CppClingo::Control::ClingoConfig::map_at | ( | KeyType | key, |
std::string_view | path | ||
) | const -> std::optional< KeyType > |
Get the key for a named subkey in a map entry.
Returns the key corresponding to the subkey with the given path in the map configuration entry specified by key
. Returns std::nullopt if the key does not exist.
key | key of the map entry |
path | path of the subkey |
auto CppClingo::Control::ClingoConfig::map_nth | ( | KeyType | key, |
KeyType | index | ||
) | const -> std::string_view |
Get the name of the nth subkey in a map entry.
Returns the name of the subkey at the given index in the map configuration entry specified by key
. Throws if the index is out of bounds.
key | key of the map entry |
index | index of the subkey |
void CppClingo::Control::ClingoConfig::set_value | ( | KeyType | key, |
std::string_view | value | ||
) |
Set the value of a configuration entry.
Sets the value associated with the given configuration key. Throws if the key cannot be set or the value is invalid.
key | key of the configuration entry |
value | value to set |
void CppClingo::Control::ClingoConfig::str | ( | Util::OutputBuffer & | out, |
KeyType | key | ||
) | const |
Get the string representation of a configuration tree.
out | the output buffer for the string representation |
key | the key to start from |