Clingo
Loading...
Searching...
No Matches
CppClingo::Control::ClingoConfig Class Reference

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.
 

Detailed Description

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.

Member Typedef Documentation

◆ KeyType

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.

Member Enumeration Documentation

◆ ValueFlags

enum class CppClingo::Control::ClingoConfig::ValueFlags : uint8_t
strong

The available value types of configuration entries.

Enumerator
none 

The entry cannot have a value.

set 

The entry can be set.

Constructor & Destructor Documentation

◆ ClingoConfig()

CppClingo::Control::ClingoConfig::ClingoConfig ( Clasp::Cli::ClaspCliConfig &  config)
inline

Constructor for ClingoConfig.

Parameters
configa reference to the Clasp CLI configuration object

Member Function Documentation

◆ add_entry()

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.

Parameters
keyparent clingo key under which the new key is added
namename of the key
descriptiondescription string for the key
entryoptional entry to handle arrays and values

◆ array_at()

auto CppClingo::Control::ClingoConfig::array_at ( KeyType  key,
KeyType  index 
) const -> KeyType

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.

Parameters
keykey of the array entry
indexindex of the array element
Returns
key for the array element at the given index

◆ description()

auto CppClingo::Control::ClingoConfig::description ( KeyType  key) const -> std::string_view

Get the description of a configuration entry.

Parameters
keykey of the configuration entry
Returns
a string view of the description

◆ get_value()

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.

Parameters
keykey of the configuration entry
Returns
value of the configuration entry

◆ key_info()

void CppClingo::Control::ClingoConfig::key_info ( KeyType  key,
int *  n_children,
int *  array_info,
ValueFlags value_info 
) const

Retrieves information about the specified key.

Note
All out parameters are optional (i.e., can be null).
Parameters
keya handle to a key
n_childrenthe number of subkeys for this key
array_infothe length of array keys or -1 for non-array keys
value_infowhether the key has a value, can be read, and can be set

◆ map_at()

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.

Parameters
keykey of the map entry
pathpath of the subkey
Returns
key for the named subkey

◆ map_nth()

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.

Parameters
keykey of the map entry
indexindex of the subkey
Returns
name of the nth subkey

◆ set_value()

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.

Parameters
keykey of the configuration entry
valuevalue to set

◆ str()

void CppClingo::Control::ClingoConfig::str ( Util::OutputBuffer out,
KeyType  key 
) const

Get the string representation of a configuration tree.

Parameters
outthe output buffer for the string representation
keythe key to start from

The documentation for this class was generated from the following file: