NAWA 0.9
Web Application Framework for C++
nawa::Config Class Reference

#include <nawa/config/Config.h>

Public Member Functions

virtual ~Config ()
 
 Config ()
 
 Config (Config const &other)
 
 Config (Config &&other) noexcept
 
Configoperator= (const Config &other)
 
Configoperator= (Config &&other) noexcept
 
 Config (std::string const &iniFile)
 
 Config (std::initializer_list< std::pair< std::pair< std::string, std::string >, std::string > > init)
 
void read (std::string const &iniFile)
 
void insert (std::initializer_list< std::pair< std::pair< std::string, std::string >, std::string > > init)
 
void override (std::vector< std::pair< std::pair< std::string, std::string >, std::string > > const &overrides)
 
bool isSet (std::pair< std::string, std::string > const &key) const
 
std::string operator[] (std::pair< std::string, std::string > const &key) const
 
void set (std::pair< std::string, std::string > key, std::string value)
 
void set (std::string section, std::string key, std::string value)
 

Detailed Description

Reader for config files and accessor to config values.

Definition at line 35 of file Config.h.

Constructor & Destructor Documentation

◆ ~Config()

virtual nawa::Config::~Config ( )
virtual

◆ Config() [1/5]

nawa::Config::Config ( )

◆ Config() [2/5]

nawa::Config::Config ( Config const &  other)

◆ Config() [3/5]

nawa::Config::Config ( Config &&  other)
noexcept

◆ Config() [4/5]

Config::Config ( std::string const &  iniFile)
explicit

Construct Config container and directly parse an ini file. Throws an Exception on failure.

Parameters
iniFileini file to parse, values will be added to the Config container.

Definition at line 54 of file Config.cpp.

◆ Config() [5/5]

Config::Config ( std::initializer_list< std::pair< std::pair< std::string, std::string >, std::string > >  init)

Construct Config container based on values from an initializer list.

Parameters
initInitializer list containing key-value pairs, wherein the keys are section-key pairs.

Definition at line 50 of file Config.cpp.

Member Function Documentation

◆ operator=() [1/2]

Config & nawa::Config::operator= ( const Config other)

◆ operator=() [2/2]

Config & nawa::Config::operator= ( Config &&  other)
noexcept

◆ read()

void Config::read ( std::string const &  iniFile)

Read an ini file and add the values to the Config container. If a key is already set, the element will be ignored, not overwritten. Throws a SysException on failure.

Parameters
iniFileini file to parse and import values from.

Definition at line 58 of file Config.cpp.

◆ insert()

void Config::insert ( std::initializer_list< std::pair< std::pair< std::string, std::string >, std::string > >  init)

Insert values from an initializer list. If a key is already set, the element will be ignored, not overwritten.

Parameters
initInitializer list containing key-value pairs, wherein the keys are section-key pairs.

Definition at line 71 of file Config.cpp.

◆ override()

void Config::override ( std::vector< std::pair< std::pair< std::string, std::string >, std::string > > const &  overrides)

Sets the elements form the vector to the given values (or inserts them, if they did not exist yet).

Parameters
overridesVector containing key-value pairs, wherein the keys are section-key pairs.

Definition at line 75 of file Config.cpp.

◆ isSet()

bool Config::isSet ( std::pair< std::string, std::string > const &  key) const

Check whether a key exists in this Config container.

Parameters
keyKey (pair of section and name of the value) to check for.
Returns
True if the key exists, false if not.

Definition at line 81 of file Config.cpp.

◆ operator[]()

std::string Config::operator[] ( std::pair< std::string, std::string > const &  key) const

Get the value belonging to the specified key from the Config container.

Parameters
keyKey (pair of section and name of the value).
Returns
The value belonging to the key if it exists, an empty string otherwise (for distinguishing between an empty value and a non-existing one, use the isSet() function).

Definition at line 85 of file Config.cpp.

◆ set() [1/2]

void Config::set ( std::pair< std::string, std::string >  key,
std::string  value 
)

Set a key to a new value or insert a new key with the given value.

Parameters
keyPair of section and key string identifying the Config value that is to be set.
valueThe value to set.

Definition at line 94 of file Config.cpp.

◆ set() [2/2]

void Config::set ( std::string  section,
std::string  key,
std::string  value 
)

Set a key to a new value or insert a new key with the given value.

Parameters
sectionThe config section in which the key is located.
keyThe key.
valueThe value to set.

Definition at line 98 of file Config.cpp.


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