Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
bitpit::Config Class Reference

Configuration storage. More...

Inheritance diagram for bitpit::Config:
Inheritance graph
[legend]

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)
 
SectionaddSection (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 >
get (const std::string &key) const
 
std::string get (const std::string &key, const std::string &fallback) const
 
template<typename T >
get (const std::string &key, const T &fallback) const
 
int getOptionCount () const
 
Options & getOptions ()
 
const Options & getOptions () const
 
SectiongetSection (const std::string &key)
 
const SectiongetSection (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
 
Configoperator= (Config &&other)=default
 
Configoperator= (Config other)
 
Sectionoperator[] (const std::string &key)
 
const Sectionoperator[] (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
 

Detailed Description

Configuration storage.

This class implements a configuration storage.

Examples
POD_application_example_00001.cpp.

Definition at line 35 of file configuration_config.hpp.

Member Typedef Documentation

◆ ConstMultiSection

typedef std::vector<const Section *> bitpit::Config::ConstMultiSection

Definition at line 41 of file configuration_config.hpp.

◆ MultiSection

typedef std::vector<Section *> bitpit::Config::MultiSection

Definition at line 40 of file configuration_config.hpp.

◆ Options

typedef std::map<std::string, std::string> bitpit::Config::Options

Definition at line 42 of file configuration_config.hpp.

◆ Section

Definition at line 39 of file configuration_config.hpp.

◆ Sections

typedef std::multimap<std::string, std::unique_ptr<Config> > bitpit::Config::Sections

Definition at line 43 of file configuration_config.hpp.

Constructor & Destructor Documentation

◆ Config() [1/2]

bitpit::Config::Config ( bool multiSections = false)

Create a new configuration.

Parameters
multiSectionsif set to true the configuration will allow multiple sections with the same name

Definition at line 46 of file configuration_config.cpp.

◆ Config() [2/2]

bitpit::Config::Config ( const Config & other)

Copy constructor.

Parameters
otheris the object to be copied

Definition at line 58 of file configuration_config.cpp.

Member Function Documentation

◆ addSection()

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.

Parameters
keyis the name of the section
Returns
A reference to the newly added section.

Definition at line 330 of file configuration_config.cpp.

◆ clear()

void bitpit::Config::clear ( )

Clear the configuration.

Definition at line 356 of file configuration_config.cpp.

◆ dump()

void bitpit::Config::dump ( std::ostream & out,
int indentLevel = 0 ) const

Write the specified configuration to screen.

Parameters
outis the stream where the configuration will be written
indentLevelis the indentation level

Definition at line 394 of file configuration_config.cpp.

◆ get() [1/4]

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.

Parameters
keyis the name of the option
Returns
The specified option.
Examples
POD_application_example_00001.cpp.

Definition at line 154 of file configuration_config.cpp.

◆ get() [2/4]

template<typename T >
T bitpit::Config::get ( const std::string & key) const

Gets the specified option.

If the option does not exists an exception is thrown.

Parameters
keyis the name of the option
Returns
The specified option.

Definition at line 41 of file configuration_config.tpp.

◆ get() [3/4]

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.

Parameters
keyis the name of the option
fallbackis the value that will be returned if the specified options does not exist
Returns
The specified option or the fallback value if the specified options does not exist.

Definition at line 170 of file configuration_config.cpp.

◆ get() [4/4]

template<typename T >
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.

Parameters
keyis the name of the option
fallbackis the value that will be returned if the specified options does not exist
Returns
The specified option or the fallback value if the specified options does not exist.

Definition at line 63 of file configuration_config.tpp.

◆ getOptionCount()

int bitpit::Config::getOptionCount ( ) const

Count the number of options.

Returns
The number of options stored.

Definition at line 110 of file configuration_config.cpp.

◆ getOptions() [1/2]

Config::Options & bitpit::Config::getOptions ( )

Gets a reference to the stored options.

Returns
A reference to the stored options.

Definition at line 120 of file configuration_config.cpp.

◆ getOptions() [2/2]

const Config::Options & bitpit::Config::getOptions ( ) const

Gets a constant reference to the stored options.

Returns
A constant reference to the stored options.

Definition at line 130 of file configuration_config.cpp.

◆ getSection() [1/2]

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.

Parameters
keyis the name of the section
Returns
A reference to the specified section.
Examples
POD_application_example_00001.cpp.

Definition at line 299 of file configuration_config.cpp.

◆ getSection() [2/2]

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.

Parameters
keyis the name of the section
Returns
A constant reference to the specified section.

Definition at line 312 of file configuration_config.cpp.

◆ getSectionCount() [1/2]

int bitpit::Config::getSectionCount ( ) const

Count the number of sections.

Returns
The number of sections stored.

Definition at line 206 of file configuration_config.cpp.

◆ getSectionCount() [2/2]

int bitpit::Config::getSectionCount ( const std::string & key) const

Count the number of sections with the specified name.

Parameters
keyis the name of the section
Returns
The number of sections with the specified name.

Definition at line 217 of file configuration_config.cpp.

◆ getSections() [1/4]

Config::Sections & bitpit::Config::getSections ( )

Gets a reference to the stored sections.

Returns
A reference to the stored sections.

Definition at line 227 of file configuration_config.cpp.

◆ getSections() [2/4]

const Config::Sections & bitpit::Config::getSections ( ) const

Gets a constant reference to the stored options.

Returns
A constant reference to the stored options.

Definition at line 237 of file configuration_config.cpp.

◆ getSections() [3/4]

Config::MultiSection bitpit::Config::getSections ( const std::string & key)

Gets a list of pointers to the sections with the specified name.

Parameters
keyis the name of the section
Returns
A list of pointers to the sections with the specified name.

Definition at line 248 of file configuration_config.cpp.

◆ getSections() [4/4]

Config::ConstMultiSection bitpit::Config::getSections ( const std::string & key) const

Gets a list of constant pointers to the sections with the specified name.

Parameters
keyis the name of the section
Returns
A list of constant pointers to the sections with the specified name.

Definition at line 267 of file configuration_config.cpp.

◆ hasOption()

bool bitpit::Config::hasOption ( const std::string & key) const

Checks if the specified option exists.

Parameters
keyis the name of the option
Returns
True is the option exists, false otherwise.
Examples
POD_application_example_00001.cpp.

Definition at line 141 of file configuration_config.cpp.

◆ hasSection()

bool bitpit::Config::hasSection ( const std::string & key) const

Checks if the specified section exists.

Parameters
keyis the name of the section
Returns
True is the section exists, false otherwise.

Definition at line 286 of file configuration_config.cpp.

◆ isMultiSectionsEnabled()

bool bitpit::Config::isMultiSectionsEnabled ( ) const

Returns true if multi-sections are enabled.

Returns
Returns true if multi-sections are enabled.

Definition at line 100 of file configuration_config.cpp.

◆ operator=()

Config & bitpit::Config::operator= ( Config other)

Copy assigment operator.

Parameters
otheris the object to be copied

Definition at line 74 of file configuration_config.cpp.

◆ operator[]() [1/2]

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.

Parameters
keyis the name of the section
Returns
A reference to the specified section.

Definition at line 383 of file configuration_config.cpp.

◆ operator[]() [2/2]

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.

Parameters
keyis the name of the section
Returns
A constant reference to the specified section.

Definition at line 370 of file configuration_config.cpp.

◆ removeOption()

bool bitpit::Config::removeOption ( const std::string & key)

Remove the specified option.

Parameters
keyis the name of the option
Returns
Returns true if the option existed, otherwise it returns false.

Definition at line 196 of file configuration_config.cpp.

◆ removeSection()

bool bitpit::Config::removeSection ( const std::string & key)

Remove the specified section.

Parameters
keyis the name of the section
Returns
Returns true if the section existed, otherwise it returns false.

Definition at line 348 of file configuration_config.cpp.

◆ set() [1/2]

void bitpit::Config::set ( const std::string & key,
const std::string & value )

Set the given option to the specified value

Parameters
keyis the name of the option
valueis the value of the option

Definition at line 185 of file configuration_config.cpp.

◆ set() [2/2]

template<typename T >
void bitpit::Config::set ( const std::string & key,
const T & value )

Set the given option to the specified value

Parameters
keyis the name of the option
valueis the value of the option

Definition at line 79 of file configuration_config.tpp.

◆ swap()

void bitpit::Config::swap ( Config & other)

Swap operator.

Parameters
otheris another config whose content is swapped with that of this config

Definition at line 87 of file configuration_config.cpp.

Member Data Documentation

◆ m_multiSections

bool bitpit::Config::m_multiSections
protected

Definition at line 96 of file configuration_config.hpp.


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