CPP-TOOLBOX
Loading...
Searching...
No Matches
Configuration Class Reference

Class to parse a configuration file and apply logic based on section-key pairs. More...

#include <config_file_parser.hpp>

Classes

struct  PairHash
 Hash function for ConfigKey (pair of strings). More...
 

Public Types

using SectionKeyPair = std::pair<std::string, std::string>
 
using ConfigLogic = std::function<void(const std::string)>
 
using SectionKeyPairToConfigLogic = std::unordered_map<SectionKeyPair, ConfigLogic, PairHash>
 
using ConfigData = std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
 

Public Member Functions

 Configuration (const std::filesystem::path &config_path, const SectionKeyPairToConfigLogic &config_logic={}, bool apply=true)
 
void reload_config_from_file ()
 
void register_config_handler (const std::string &section, const std::string &key, std::function< void(const std::string)> logic)
 
bool set_value (const std::string &section, const std::string &key, const std::string &value, const bool apply=false)
 
std::optional< std::string > get_value (const std::string &section, const std::string &key)
 
bool remove_value (const std::string &section, const std::string &key)
 
bool has_section (const std::string &section) const
 
bool has_value (const std::string &section, const std::string &key)
 
std::vector< std::string > get_sections () const
 
std::vector< std::string > get_keys (const std::string &section)
 
bool save_to_file ()
 
bool save_to_file (const std::filesystem::path &path)
 
bool backup_config (const std::filesystem::path &backup_path)
 
void apply_config_logic_for_key (const std::string &section, const std::string &key)
 
void apply_config_logic ()
 

Detailed Description

Class to parse a configuration file and apply logic based on section-key pairs.

Member Typedef Documentation

◆ ConfigData

using Configuration::ConfigData = std::unordered_map<std::string, std::unordered_map<std::string, std::string>>

◆ ConfigLogic

using Configuration::ConfigLogic = std::function<void(const std::string)>

◆ SectionKeyPair

using Configuration::SectionKeyPair = std::pair<std::string, std::string>

◆ SectionKeyPairToConfigLogic

Constructor & Destructor Documentation

◆ Configuration()

Configuration::Configuration ( const std::filesystem::path & config_path,
const SectionKeyPairToConfigLogic & config_logic = {},
bool apply = true )

Member Function Documentation

◆ apply_config_logic()

void Configuration::apply_config_logic ( )

◆ apply_config_logic_for_key()

void Configuration::apply_config_logic_for_key ( const std::string & section,
const std::string & key )

◆ backup_config()

bool Configuration::backup_config ( const std::filesystem::path & backup_path)

◆ get_keys()

std::vector< std::string > Configuration::get_keys ( const std::string & section)

◆ get_sections()

std::vector< std::string > Configuration::get_sections ( ) const

◆ get_value()

std::optional< std::string > Configuration::get_value ( const std::string & section,
const std::string & key )

◆ has_section()

bool Configuration::has_section ( const std::string & section) const

◆ has_value()

bool Configuration::has_value ( const std::string & section,
const std::string & key )

◆ register_config_handler()

void Configuration::register_config_handler ( const std::string & section,
const std::string & key,
std::function< void(const std::string)> logic )

◆ reload_config_from_file()

void Configuration::reload_config_from_file ( )

◆ remove_value()

bool Configuration::remove_value ( const std::string & section,
const std::string & key )

◆ save_to_file() [1/2]

bool Configuration::save_to_file ( )

◆ save_to_file() [2/2]

bool Configuration::save_to_file ( const std::filesystem::path & path)

◆ set_value()

bool Configuration::set_value ( const std::string & section,
const std::string & key,
const std::string & value,
const bool apply = false )

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