Clio develop
The XRP Ledger API server.
|
Convenience wrapper to query a JSON configuration file. More...
#include <Config.hpp>
Public Types | |
using | KeyType = std::string |
using | ArrayType = std::vector<Config> |
using | WriteCursorType = std::pair<std::optional<std::reference_wrapper<boost::json::value>>, KeyType> |
Public Member Functions | |
Config (boost::json::value store={}) | |
Construct a new Config object. | |
operator bool () const noexcept | |
Checks whether underlying store is not null. | |
bool | contains (KeyType key) const |
Checks whether something exists under given key. | |
template<typename Result > | |
std::optional< Result > | maybeValue (KeyType key) const |
Interface for fetching values by key that returns std::optional. | |
template<typename Result > | |
Result | value (KeyType key) const |
Interface for fetching values by key. | |
template<typename Result > | |
Result | valueOr (KeyType key, Result fallback) const |
Interface for fetching values by key with fallback. | |
template<typename Result > | |
Result | valueOrThrow (KeyType key, std::string_view err) const |
Interface for fetching values by key with custom error handling. | |
std::optional< ArrayType > | maybeArray (KeyType key) const |
Interface for fetching an array by key that returns std::optional. | |
ArrayType | array (KeyType key) const |
Interface for fetching an array by key. | |
ArrayType | arrayOr (KeyType key, ArrayType fallback) const |
Interface for fetching an array by key with fallback. | |
ArrayType | arrayOrThrow (KeyType key, std::string_view err) const |
Interface for fetching an array by key with custom error handling. | |
Config | section (KeyType key) const |
Interface for fetching a sub section by key. | |
Config | sectionOr (KeyType key, boost::json::object fallback) const |
Interface for fetching a sub section by key with a fallback object. | |
template<typename Result > | |
std::optional< Result > | maybeValue () const |
Interface for reading the value directly referred to by the instance. Wraps as std::optional. | |
template<typename Result > | |
Result | value () const |
Interface for reading the value directly referred to by the instance. | |
template<typename Result > | |
Result | valueOr (Result fallback) const |
Interface for reading the value directly referred to by the instance with user-specified fallback. | |
template<typename Result > | |
Result | valueOrThrow (std::string_view err) const |
Interface for reading the value directly referred to by the instance with user-specified error message. | |
ArrayType | array () const |
Interface for reading the array directly referred to by the instance. | |
Static Public Member Functions | |
static std::chrono::milliseconds | toMilliseconds (float value) |
Method to convert a float seconds value to milliseconds. | |
Convenience wrapper to query a JSON configuration file.
Any custom data type can be supported by implementing the right tag_invoke
for boost::json::value_to
.
|
explicit |
Construct a new Config object.
store | boost::json::value that backs this instance |
|
nodiscard |
Interface for reading the array directly referred to by the instance.
See array(KeyType) const for how this works.
|
nodiscard |
Interface for fetching an array by key.
Will attempt to fetch an array under the desired key. If the array exists then it will be returned. If the array does not exist under the specified key an std::logic_error is thrown.
key | The key to check |
std::logic_error | Thrown if there is no array under the desired key or the key is of invalid format |
|
nodiscard |
Interface for fetching an array by key with fallback.
Will attempt to fetch an array under the desired key. If the array exists then it will be returned. If the array does not exist or another type is stored under the desired key - user specified fallback is returned.
key | The key to check |
fallback | The fallback array |
std::logic_error | Thrown if the key is of invalid format |
|
nodiscard |
Interface for fetching an array by key with custom error handling.
Will attempt to fetch an array under the desired key. If the array exists then it will be returned. If the array does not exist or another type is stored under the desired key - std::runtime_error is thrown with the user specified error message.
key | The key to check |
err | The custom error message |
std::runtime_error | Thrown if there is no array under the desired key |
|
nodiscard |
Checks whether something exists under given key.
key | The key to check |
std::logic_error | If the key is of invalid format |
|
nodiscard |
Interface for fetching an array by key that returns std::optional.
Will attempt to fetch an array under the desired key. If the array exists then it will be returned wrapped in an optional. If the array does not exist under the specified key - std::nullopt is returned.
key | The key to check |
std::logic_error | Thrown if the key is of invalid format |
|
inlinenodiscard |
Interface for reading the value directly referred to by the instance. Wraps as std::optional.
See maybeValue(KeyType) const for how this works.
|
inlinenodiscard |
Interface for fetching values by key that returns std::optional.
Will attempt to fetch the value under the desired key. If the value exists and can be represented by the desired type Result then it will be returned wrapped in an optional. If the value exists but the conversion to Result is not possible - a runtime_error will be thrown. If the value does not exist under the specified key - std::nullopt is returned.
Result | The desired return type |
key | The key to check |
std::logic_error | Thrown if conversion to Result is not possible or key is of invalid format |
|
noexcept |
Checks whether underlying store is not null.
|
nodiscard |
Interface for fetching a sub section by key.
Will attempt to fetch an entire section under the desired key and return it as a Config instance. If the section does not exist or another type is stored under the desired key - std::logic_error is thrown.
key | The key to check |
std::logic_error | Thrown if there is no section under the desired key or the key is of invalid format |
|
nodiscard |
Interface for fetching a sub section by key with a fallback object.
Will attempt to fetch an entire section under the desired key and return it as a Config instance. If the section does not exist or another type is stored under the desired key - fallback object is used instead.
key | The key to check |
fallback | The fallback object |
|
static |
Method to convert a float seconds value to milliseconds.
value | The value to convert |
|
inlinenodiscard |
Interface for reading the value directly referred to by the instance.
See value(KeyType) const for how this works.
|
inlinenodiscard |
Interface for fetching values by key.
Will attempt to fetch the value under the desired key. If the value exists and can be represented by the desired type Result then it will be returned. If the value exists but the conversion to Result is not possible OR the value does not exist - a logic_error will be thrown.
Result | The desired return type |
key | The key to check |
std::logic_error | Thrown if conversion to Result is not possible, value does not exist under specified key path or the key is of invalid format |
|
inlinenodiscard |
Interface for fetching values by key with fallback.
Will attempt to fetch the value under the desired key. If the value exists and can be represented by the desired type Result then it will be returned. If the value exists but the conversion to Result is not possible - a logic_error will be thrown. If the value does not exist under the specified key - user specified fallback is returned.
Result | The desired return type |
key | The key to check |
fallback | The fallback value |
std::logic_error | Thrown if conversion to Result is not possible or the key is of invalid format |
|
inlinenodiscard |
Interface for reading the value directly referred to by the instance with user-specified fallback.
See valueOr(KeyType, Result) const for how this works.
fallback | The fallback value |
|
inlinenodiscard |
Interface for fetching values by key with custom error handling.
Will attempt to fetch the value under the desired key. If the value exists and can be represented by the desired type Result then it will be returned. If the value exists but the conversion to Result is not possible OR the value does not exist - a runtime_error will be thrown with the user specified message.
Result | The desired return type |
key | The key to check |
err | The custom error message |
std::runtime_error | Thrown if conversion to Result is not possible or value does not exist under key |
|
inlinenodiscard |
Interface for reading the value directly referred to by the instance with user-specified error message.
See valueOrThrow(KeyType, std::string_view) const for how this works.
err | The custom error message |