peary::config::Configuration

Configuration class holding key-value pairs of configuration parameters.

#include <peary/config/configuration.hpp>

Public Functions

Name
Configuration() =defaultDefault constructor.
Configuration(const std::string & section_name)Constructor with section name.
Configuration(const Configuration & other)Copy constructor.
void Add(const std::string & key, const std::string & value)Add new key-value pair to config. Already existing values with the same key will be overwritten.
std::string operator[](const std::string & key) const
bool Has(const std::string & key) const
std::string Get(const std::string & key, const std::string & def) constGet configuration value via its key, with a default value if the key does not exist.
double Get(const std::string & key, double def) constGet configuration value via its key, with a default value if the key does not exist.
int64_t Get(const std::string & key, int64_t def) constGet configuration value via its key, with a default value if the key does not exist.
uint64_t Get(const std::string & key, uint64_t def) constGet configuration value via its key, with a default value if the key does not exist.
template <typename T > T Get(const std::string & key) constGet configuration value via its key, converted to the requested type.
template <typename T > T Get(const std::string & key, T def) constGet configuration value via its key, with a default value if the key does not exist, converted to the requested type.
template <typename T > std::vector< T > Get(const std::string & key, std::vector< T > def) constGet configuration value via its key, split into a vector of the requested type.
int Get(const std::string & key, int def) constGet configuration value via its key, with a default value if the key does not exist.
template <typename T > T Get(const std::string & key, const std::string fallback, const T & def) constGet configuration value via its key, with a fallback key if the main key does not exist.
std::string Get(const std::string & key, const char * def) constGet configuration value via its key, with a default value if the key does not exist.
std::string Get(const std::string & key, const std::string & fallback, const std::string & def) constGet configuration value via its key, with a fallback key if the main key does not exist.
template <typename T > void Set(const std::string & key, const T & val)Set configuration value via its key, converting the value to string.
bool empty() constCheck if this configuration is empty.
std::string Section() constGet the section name of this configuration.
Configuration & operator=(const Configuration & other)Assignment operator.
void Print(std::ostream & out) constPrint the configuration to a given output stream.
void Print() constPrint the configuration to standard output.

Friends

Name
std::ostream & operator«(std::ostream & os, const Configuration & c) Overloaded output operator for Configuration objects.

Public Functions Documentation

function Configuration

  Configuration() =default
  

Default constructor.

function Configuration

  inline Configuration(
    const std::string & section_name
)
  

Constructor with section name.

Parameters:

  • section_name Name of the section this configuration belongs to

function Configuration

  Configuration(
    const Configuration & other
)
  

Copy constructor.

Parameters:

function Add

  void Add(
    const std::string & key,
    const std::string & value
)
  

Add new key-value pair to config. Already existing values with the same key will be overwritten.

Parameters:

  • key Kay of the new parameter
  • value Value of the new parameter

function operator[]

  inline std::string operator[](
    const std::string & key
) const
  

function Has

  bool Has(
    const std::string & key
) const
  

function Get

  std::string Get(
    const std::string & key,
    const std::string & def
) const
  

Get configuration value via its key, with a default value if the key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Return: Value of the parameter as string or the default value if the key does not exist

function Get

  double Get(
    const std::string & key,
    double def
) const
  

Get configuration value via its key, with a default value if the key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Return: Value of the parameter as double or the default value if the key does not exist

function Get

  int64_t Get(
    const std::string & key,
    int64_t def
) const
  

Get configuration value via its key, with a default value if the key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Return: Value of the parameter as int64_t or the default value if the key does not exist

function Get

  uint64_t Get(
    const std::string & key,
    uint64_t def
) const
  

Get configuration value via its key, with a default value if the key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Return: Value of the parameter as uint64_t or the default value if the key does not exist

function Get

  template <typename T >
inline T Get(
    const std::string & key
) const
  

Get configuration value via its key, converted to the requested type.

Parameters:

  • key Key of the parameter to be accessed

Return: Value of the parameter converted to the requested type

function Get

  template <typename T >
inline T Get(
    const std::string & key,
    T def
) const
  

Get configuration value via its key, with a default value if the key does not exist, converted to the requested type.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Template Parameters:

  • T Type to which the value should be converted

Return: Value of the parameter converted to the requested type or the default value if the key does not

function Get

  template <typename T >
inline std::vector< T > Get(
    const std::string & key,
    std::vector< T > def
) const
  

Get configuration value via its key, split into a vector of the requested type.

Parameters:

  • key Key of the parameter to be accessed
  • def Default vector to be returned if the key does not exist or the value is empty

Template Parameters:

  • T Type to which the individual values should be converted

Return: Vector of values of the requested type

function Get

  int Get(
    const std::string & key,
    int def
) const
  

Get configuration value via its key, with a default value if the key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Return: Value of the parameter as int or the default value if the key does not exist

function Get

  template <typename T >
inline T Get(
    const std::string & key,
    const std::string fallback,
    const T & def
) const
  

Get configuration value via its key, with a fallback key if the main key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • fallback Fallback key to be used if the main key does not exist
  • def Default value to be returned if neither the main key nor the fallback key exist

Template Parameters:

  • T Type to which the value should be converted

Return: Value of the parameter as the requested type or the default value if neither the main key nor the fallback key exist

function Get

  inline std::string Get(
    const std::string & key,
    const char * def
) const
  

Get configuration value via its key, with a default value if the key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • def Default value to be returned if the key does not exist

Return: Value of the parameter as string or the default value if the key does not exist

function Get

  inline std::string Get(
    const std::string & key,
    const std::string & fallback,
    const std::string & def
) const
  

Get configuration value via its key, with a fallback key if the main key does not exist.

Parameters:

  • key Key of the parameter to be accessed
  • fallback Fallback key to be used if the main key does not exist
  • def Default value to be returned if neither the main key nor the fallback key exist

Return: Value of the parameter as string or the default value if neither the main key nor the fallback key exist

function Set

  template <typename T >
inline void Set(
    const std::string & key,
    const T & val
)
  

Set configuration value via its key, converting the value to string.

Parameters:

  • key Key of the parameter to be set
  • val Value to be set

Template Parameters:

  • T Type of the value to be set

function empty

  inline bool empty() const
  

Check if this configuration is empty.

Return: True if empty, false otherwise

function Section

  inline std::string Section() const
  

Get the section name of this configuration.

Return: Section name

function operator=

  Configuration & operator=(
    const Configuration & other
)
  

Assignment operator.

Parameters:

function Print

  void Print(
    std::ostream & out
) const
  

Print the configuration to a given output stream.

Parameters:

  • out Output stream to print to

function Print

  void Print() const
  

Print the configuration to standard output.

Friends

friend operator«

  friend std::ostream & operator<<(
    std::ostream & os,

    const Configuration & c
);
  

Overloaded output operator for Configuration objects.

Parameters:

  • os Output stream to write to
  • c Configuration object to be printed

Return: Reference to the output stream


Updated on 2025-11-14 at 11:31:23 +0100