Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util::config::ClioConfigDefinition Class Reference

All the config data will be stored and extracted from this class. More...

#include <ConfigDefinition.hpp>

Public Types

using KeyValuePair = std::pair<std::string_view, std::variant<ConfigValue, Array>>
 

Public Member Functions

 ClioConfigDefinition (std::initializer_list< KeyValuePair > pair)
 Constructs a new ClioConfigDefinition.
 
std::optional< std::vector< Error > > parse (ConfigFileInterface const &config)
 Parses the configuration file.
 
ObjectView getObject (std::string_view prefix, std::optional< std::size_t > idx=std::nullopt) const
 Returns the ObjectView specified with the prefix.
 
ValueView getValueView (std::string_view fullKey) const
 Returns the specified ValueView object associated with the key.
 
template<typename T >
get (std::string_view fullKey) const
 Returns the specified value of given string if value exists.
 
ValueView getValueInArray (std::string_view fullKey, std::size_t index) const
 Returns the specified ValueView object in an array with a given index.
 
ArrayView getArray (std::string_view prefix) const
 Returns the specified Array object from ClioConfigDefinition.
 
bool contains (std::string_view key) const
 Checks if a key is present in the configuration map.
 
bool hasItemsWithPrefix (std::string_view key) const
 Checks if any key in config starts with "key".
 
Array const & asArray (std::string_view key) const
 Returns the Array object associated with the specified key.
 
std::size_t arraySize (std::string_view prefix) const
 Returns the size of an Array.
 
template<typename T >
std::optional< T > maybeValue (std::string_view fullKey) const
 Returns the specified value of given string of type T if type and value exists.
 
auto begin () const
 Returns an iterator to the beginning of the configuration map.
 
auto end () const
 Returns an iterator to the end of the configuration map.
 

Static Public Member Functions

static std::chrono::milliseconds toMilliseconds (float value)
 Method to convert a float seconds value to milliseconds.
 

Detailed Description

All the config data will be stored and extracted from this class.

Represents all the possible config data

Constructor & Destructor Documentation

◆ ClioConfigDefinition()

util::config::ClioConfigDefinition::ClioConfigDefinition ( std::initializer_list< KeyValuePair > pair)

Constructs a new ClioConfigDefinition.

Initializes the configuration with a predefined set of key-value pairs If a key contains "[]", the corresponding value must be an Array

Parameters
pairA list of key-value pairs for the predefined set of clio configurations

Member Function Documentation

◆ arraySize()

std::size_t util::config::ClioConfigDefinition::arraySize ( std::string_view prefix) const
nodiscard

Returns the size of an Array.

Parameters
prefixThe prefix whose associated Array object is to be returned.
Returns
The size of the array associated with the specified prefix.

◆ asArray()

Array const & util::config::ClioConfigDefinition::asArray ( std::string_view key) const
nodiscard

Returns the Array object associated with the specified key.

Parameters
keyThe key whose associated Array object is to be returned.
Returns
The Array object associated with the specified key.

◆ begin()

auto util::config::ClioConfigDefinition::begin ( ) const
inlinenodiscard

Returns an iterator to the beginning of the configuration map.

Returns
A constant iterator to the beginning of the map.

◆ contains()

bool util::config::ClioConfigDefinition::contains ( std::string_view key) const
nodiscard

Checks if a key is present in the configuration map.

Parameters
keyThe key to search for in the configuration map.
Returns
True if the key is present, false otherwise.

◆ end()

auto util::config::ClioConfigDefinition::end ( ) const
inlinenodiscard

Returns an iterator to the end of the configuration map.

Returns
A constant iterator to the end of the map.

◆ get()

template<typename T >
T util::config::ClioConfigDefinition::get ( std::string_view fullKey) const
inline

Returns the specified value of given string if value exists.

Template Parameters
TThe type T to return
Parameters
fullKeyThe config key to search for
Returns
Value of key of type T

◆ getArray()

ArrayView util::config::ClioConfigDefinition::getArray ( std::string_view prefix) const
nodiscard

Returns the specified Array object from ClioConfigDefinition.

Parameters
prefixThe prefix to search config keys from
Returns
ArrayView with all key-value pairs where key starts with "prefix"

◆ getObject()

ObjectView util::config::ClioConfigDefinition::getObject ( std::string_view prefix,
std::optional< std::size_t > idx = std::nullopt ) const
nodiscard

Returns the ObjectView specified with the prefix.

Parameters
prefixThe key prefix for the ObjectView
idxUsed if getting Object in an Array
Returns
ObjectView with the given prefix

◆ getValueInArray()

ValueView util::config::ClioConfigDefinition::getValueInArray ( std::string_view fullKey,
std::size_t index ) const
nodiscard

Returns the specified ValueView object in an array with a given index.

Parameters
fullKeyThe config key to search for
indexThe index of the config value inside the Array to get
Returns
ValueView associated with the given key

◆ getValueView()

ValueView util::config::ClioConfigDefinition::getValueView ( std::string_view fullKey) const
nodiscard

Returns the specified ValueView object associated with the key.

Parameters
fullKeyThe config key to search for
Returns
ValueView associated with the given key

◆ hasItemsWithPrefix()

bool util::config::ClioConfigDefinition::hasItemsWithPrefix ( std::string_view key) const
nodiscard

Checks if any key in config starts with "key".

Parameters
keyThe key to search for in the configuration map.
Returns
True if the any key in config starts with "key", false otherwise.

◆ maybeValue()

template<typename T >
std::optional< T > util::config::ClioConfigDefinition::maybeValue ( std::string_view fullKey) const
inline

Returns the specified value of given string of type T if type and value exists.

Template Parameters
TThe type T to return
Parameters
fullKeyThe config key to search for
Returns
The value of type T if it exists, std::nullopt otherwise.

◆ parse()

std::optional< std::vector< Error > > util::config::ClioConfigDefinition::parse ( ConfigFileInterface const & config)
nodiscard

Parses the configuration file.

Also checks that no extra configuration key/value pairs are present. Adds to list of Errors if it does

Parameters
configThe configuration file interface
Returns
An optional vector of Error objects stating all the failures if parsing fails

◆ toMilliseconds()

std::chrono::milliseconds util::config::ClioConfigDefinition::toMilliseconds ( float value)
static

Method to convert a float seconds value to milliseconds.

Parameters
valueThe value to convert
Returns
The value in milliseconds

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