Configuration storage. More...
Public Types | |
typedef std::vector< const Section * > | ConstMultiSection |
typedef std::vector< Section * > | MultiSection |
typedef std::map< std::string, std::string > | Options |
typedef Config | Section |
typedef std::multimap< std::string, std::unique_ptr< Config > > | Sections |
Public Member Functions | |
Config (bool multiSections=false) | |
Config (Config &&other)=default | |
Config (const Config &other) | |
Section & | addSection (const std::string &key) |
void | clear () |
void | dump (std::ostream &out, int indentLevel=0) const |
const std::string & | get (const std::string &key) const |
template<typename T > | |
T | get (const std::string &key) const |
std::string | get (const std::string &key, const std::string &fallback) const |
template<typename T > | |
T | get (const std::string &key, const T &fallback) const |
int | getOptionCount () const |
Options & | getOptions () |
const Options & | getOptions () const |
Section & | getSection (const std::string &key) |
const Section & | getSection (const std::string &key) const |
int | getSectionCount () const |
int | getSectionCount (const std::string &key) const |
Sections & | getSections () |
const Sections & | getSections () const |
MultiSection | getSections (const std::string &key) |
ConstMultiSection | getSections (const std::string &key) const |
bool | hasOption (const std::string &key) const |
bool | hasSection (const std::string &key) const |
bool | isMultiSectionsEnabled () const |
Config & | operator= (Config &&other)=default |
Config & | operator= (Config other) |
Section & | operator[] (const std::string &key) |
const Section & | operator[] (const std::string &key) const |
bool | removeOption (const std::string &key) |
bool | removeSection (const std::string &key) |
void | set (const std::string &key, const std::string &value) |
template<typename T > | |
void | set (const std::string &key, const T &value) |
void | swap (Config &other) |
Protected Attributes | |
bool | m_multiSections |
Configuration storage.
This class implements a configuration storage.
Definition at line 35 of file configuration_config.hpp.
typedef std::vector<const Section *> bitpit::Config::ConstMultiSection |
Definition at line 41 of file configuration_config.hpp.
typedef std::vector<Section *> bitpit::Config::MultiSection |
Definition at line 40 of file configuration_config.hpp.
typedef std::map<std::string, std::string> bitpit::Config::Options |
Definition at line 42 of file configuration_config.hpp.
typedef Config bitpit::Config::Section |
Definition at line 39 of file configuration_config.hpp.
typedef std::multimap<std::string, std::unique_ptr<Config> > bitpit::Config::Sections |
Definition at line 43 of file configuration_config.hpp.
bitpit::Config::Config | ( | bool | multiSections = false | ) |
Create a new configuration.
multiSections | if set to true the configuration will allow multiple sections with the same name |
Definition at line 46 of file configuration_config.cpp.
bitpit::Config::Config | ( | const Config & | other | ) |
Copy constructor.
other | is the object to be copied |
Definition at line 58 of file configuration_config.cpp.
Config::Section & bitpit::Config::addSection | ( | const std::string & | key | ) |
Add a section with the specified name.
If a section with the given name already exists, an exception is raised.
key | is the name of the section |
Definition at line 330 of file configuration_config.cpp.
void bitpit::Config::clear | ( | ) |
Clear the configuration.
Definition at line 356 of file configuration_config.cpp.
void bitpit::Config::dump | ( | std::ostream & | out, |
int | indentLevel = 0 ) const |
Write the specified configuration to screen.
out | is the stream where the configuration will be written |
indentLevel | is the indentation level |
Definition at line 394 of file configuration_config.cpp.
const std::string & bitpit::Config::get | ( | const std::string & | key | ) | const |
Gets the specified option.
If the option does not exists an exception is thrown.
key | is the name of the option |
Definition at line 154 of file configuration_config.cpp.
T bitpit::Config::get | ( | const std::string & | key | ) | const |
Gets the specified option.
If the option does not exists an exception is thrown.
key | is the name of the option |
Definition at line 41 of file configuration_config.tpp.
std::string bitpit::Config::get | ( | const std::string & | key, |
const std::string & | fallback ) const |
Gets the specified option.
If the option does not exists the fallback value is returned.
key | is the name of the option |
fallback | is the value that will be returned if the specified options does not exist |
Definition at line 170 of file configuration_config.cpp.
T bitpit::Config::get | ( | const std::string & | key, |
const T & | fallback ) const |
Gets the specified option.
If the option does not exists the fallback value is returned.
key | is the name of the option |
fallback | is the value that will be returned if the specified options does not exist |
Definition at line 63 of file configuration_config.tpp.
int bitpit::Config::getOptionCount | ( | ) | const |
Count the number of options.
Definition at line 110 of file configuration_config.cpp.
Config::Options & bitpit::Config::getOptions | ( | ) |
Gets a reference to the stored options.
Definition at line 120 of file configuration_config.cpp.
const Config::Options & bitpit::Config::getOptions | ( | ) | const |
Gets a constant reference to the stored options.
Definition at line 130 of file configuration_config.cpp.
Config::Section & bitpit::Config::getSection | ( | const std::string & | key | ) |
Gets a reference to the specified section.
If the section does not exists an exception is thrown.
key | is the name of the section |
Definition at line 299 of file configuration_config.cpp.
const Config::Section & bitpit::Config::getSection | ( | const std::string & | key | ) | const |
Gets a constant reference to the specified section.
If the section does not exists an exception is thrown.
key | is the name of the section |
Definition at line 312 of file configuration_config.cpp.
int bitpit::Config::getSectionCount | ( | ) | const |
Count the number of sections.
Definition at line 206 of file configuration_config.cpp.
int bitpit::Config::getSectionCount | ( | const std::string & | key | ) | const |
Count the number of sections with the specified name.
key | is the name of the section |
Definition at line 217 of file configuration_config.cpp.
Config::Sections & bitpit::Config::getSections | ( | ) |
Gets a reference to the stored sections.
Definition at line 227 of file configuration_config.cpp.
const Config::Sections & bitpit::Config::getSections | ( | ) | const |
Gets a constant reference to the stored options.
Definition at line 237 of file configuration_config.cpp.
Config::MultiSection bitpit::Config::getSections | ( | const std::string & | key | ) |
Gets a list of pointers to the sections with the specified name.
key | is the name of the section |
Definition at line 248 of file configuration_config.cpp.
Config::ConstMultiSection bitpit::Config::getSections | ( | const std::string & | key | ) | const |
Gets a list of constant pointers to the sections with the specified name.
key | is the name of the section |
Definition at line 267 of file configuration_config.cpp.
bool bitpit::Config::hasOption | ( | const std::string & | key | ) | const |
Checks if the specified option exists.
key | is the name of the option |
Definition at line 141 of file configuration_config.cpp.
bool bitpit::Config::hasSection | ( | const std::string & | key | ) | const |
Checks if the specified section exists.
key | is the name of the section |
Definition at line 286 of file configuration_config.cpp.
bool bitpit::Config::isMultiSectionsEnabled | ( | ) | const |
Returns true if multi-sections are enabled.
Definition at line 100 of file configuration_config.cpp.
Copy assigment operator.
other | is the object to be copied |
Definition at line 74 of file configuration_config.cpp.
Config::Section & bitpit::Config::operator[] | ( | const std::string & | key | ) |
Get a reference of the specified section.
If the section does not exists an exception is thrown.
key | is the name of the section |
Definition at line 383 of file configuration_config.cpp.
const Config::Section & bitpit::Config::operator[] | ( | const std::string & | key | ) | const |
Get a constant reference of the specified section.
If the section does not exists an exception is thrown.
key | is the name of the section |
Definition at line 370 of file configuration_config.cpp.
bool bitpit::Config::removeOption | ( | const std::string & | key | ) |
Remove the specified option.
key | is the name of the option |
Definition at line 196 of file configuration_config.cpp.
bool bitpit::Config::removeSection | ( | const std::string & | key | ) |
Remove the specified section.
key | is the name of the section |
Definition at line 348 of file configuration_config.cpp.
void bitpit::Config::set | ( | const std::string & | key, |
const std::string & | value ) |
Set the given option to the specified value
key | is the name of the option |
value | is the value of the option |
Definition at line 185 of file configuration_config.cpp.
void bitpit::Config::set | ( | const std::string & | key, |
const T & | value ) |
Set the given option to the specified value
key | is the name of the option |
value | is the value of the option |
Definition at line 79 of file configuration_config.tpp.
void bitpit::Config::swap | ( | Config & | other | ) |
Swap operator.
other | is another config whose content is swapped with that of this config |
Definition at line 87 of file configuration_config.cpp.
|
protected |
Definition at line 96 of file configuration_config.hpp.