OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::config::parser Class Reference

Reads configuration parameters line-by-line from a file. More...

#include <config.hpp>

Public Member Functions

 parser (const std::string &filename)
 Constructor.
 
 parser (std::istream &stream)
 Constructor.
 
auto get_string (const std::string &key) const -> std::optional< std::string >
 Returns the given key if its value is a string.
 
auto get_ulong (const std::string &key) const -> std::optional< size_t >
 Return the value for the given key if its value is a long.
 
auto get_endpoint (const std::string &key) const -> std::optional< network::endpoint_t >
 Return the value for the given key if its value is an endpoint.
 
auto get_loglevel (const std::string &key) const -> std::optional< logging::log_level >
 Return the value for the given key if its value is a loglevel.
 
auto get_decimal (const std::string &key) const -> std::optional< double >
 Return the value for the given key if its value is a double.
 

Detailed Description

Reads configuration parameters line-by-line from a file.

Expects a file of line-separated parameters with each line in the form key=value, where the key is a lower-case string that may contain numbers and symbols. Acceptable value types:

  • Strings: quoted with double quotes. Ex: some_string="hello"
  • Integers: standalone numbers. Ex: some_int=30
  • Doubles: a number with a decimal point. Ex: some_double=12.4
  • Log levels: in the form of a string. Must be one of the log levels enumerated in logging.hpp, in upper-case. Ex: some_loglevel="TRACE"
  • Endpoints: strings in the form "hostname:port".

The class will override file-enumerated config parameters with values from environment variables, where the environment variable key is the upper-case version of the config file string. For example, a window_size=40000 line in the config file would be overridden by setting the environment variable WINDOW_SIZE=50000. String options supplied through environment variables must be quoted, e.g. SOMEKEY='"some_value"'. See the example configuration files and README.md for more detail and valid options.

Definition at line 323 of file config.hpp.

Constructor & Destructor Documentation

◆ parser() [1/2]

cbdc::config::parser::parser ( const std::string & filename)
explicit

Constructor.

Parameters
filenamepath to the config file to read.

Definition at line 765 of file config.cpp.

◆ parser() [2/2]

cbdc::config::parser::parser ( std::istream & stream)
explicit

Constructor.

Parameters
streamthe generic stream used to add config values.

Definition at line 772 of file config.cpp.

Member Function Documentation

◆ get_decimal()

auto cbdc::config::parser::get_decimal ( const std::string & key) const -> std::optional<double>
nodiscard

Return the value for the given key if its value is a double.

Parameters
keykey to retrieve.
Returns
value associated with the key, or std::nullopt if the value was not a double or does not exist.

Definition at line 819 of file config.cpp.

Referenced by cbdc::config::read_loadgen_options().

◆ get_endpoint()

auto cbdc::config::parser::get_endpoint ( const std::string & key) const -> std::optional<network::endpoint_t>
nodiscard

Return the value for the given key if its value is an endpoint.

Parameters
keykey to retrieve.
Returns
value associated with the key, or std::nullopt if the value was not a endpoint or does not exist.

Definition at line 800 of file config.cpp.

References cbdc::config::parse_ip_port().

Here is the call graph for this function:

◆ get_loglevel()

auto cbdc::config::parser::get_loglevel ( const std::string & key) const -> std::optional<logging::log_level>
nodiscard

Return the value for the given key if its value is a loglevel.

Parameters
keykey to retrieve.
Returns
value associated with the key, or std::nullopt if the value was not a loglevel or does not exist.

Definition at line 810 of file config.cpp.

References cbdc::logging::parse_loglevel().

Here is the call graph for this function:

◆ get_string()

auto cbdc::config::parser::get_string ( const std::string & key) const -> std::optional<std::string>
nodiscard

Returns the given key if its value is a string.

Parameters
keykey to retrieve.
Returns
value associated with the key or std::nullopt if the value was not a string or does not exist.

Definition at line 790 of file config.cpp.

◆ get_ulong()

auto cbdc::config::parser::get_ulong ( const std::string & key) const -> std::optional<size_t>
nodiscard

Return the value for the given key if its value is a long.

Parameters
keykey to retrieve.
Returns
value associated with the key, or std::nullopt if the value was not a long or doesn't exist.

Definition at line 795 of file config.cpp.

Referenced by cbdc::config::read_loadgen_options(), and cbdc::config::read_raft_options().


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