Loading...
Searching...
No Matches
Public Member Functions | List of all members
bitpit::ConfigParser Class Reference

Configuration file parser. More...

Inheritance diagram for bitpit::ConfigParser:
Inheritance graph
[legend]
Collaboration diagram for bitpit::ConfigParser:
Collaboration graph
[legend]

Public Member Functions

 ConfigParser (const std::string &rootName)
 
 ConfigParser (const std::string &rootName, bool multiSections)
 
 ConfigParser (const std::string &rootName, int version)
 
 ConfigParser (const std::string &rootName, int version, bool multiSections)
 
void read (config::SourceFormat format, const std::string &content, bool append=true)
 
void read (const std::string &filename, bool append=true)
 
void reset (const std::string &rootName)
 
void reset (const std::string &rootName, int version)
 
void reset (const std::string &rootName, int version, bool multiSections)
 
void write (config::SourceFormat format, std::string *content) const
 
void write (const std::string &filename) const
 
- Public Member Functions inherited from bitpit::Config
 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)
 

Additional Inherited Members

- Public Types inherited from bitpit::Config
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
 
- Protected Attributes inherited from bitpit::Config
bool m_multiSections
 

Detailed Description

Configuration file parser.

This class implements a configuration file parser.

Definition at line 38 of file configuration.hpp.

Constructor & Destructor Documentation

◆ ConfigParser() [1/4]

bitpit::ConfigParser::ConfigParser ( const std::string & rootName)

Construct a new configuration parser.

Parameters
rootNameis the name of the root element

Definition at line 54 of file configuration.cpp.

◆ ConfigParser() [2/4]

bitpit::ConfigParser::ConfigParser ( const std::string & rootName,
bool multiSections )

Construct a new configuration parser.

Parameters
rootNameis the name of the root element
multiSectionsif set to true the configuration parser will allow multiple sections with the same name

Definition at line 67 of file configuration.cpp.

◆ ConfigParser() [3/4]

bitpit::ConfigParser::ConfigParser ( const std::string & rootName,
int version )

Construct a new configuration parser.

Parameters
rootNameis the name of the root element
versionis the required version

Definition at line 79 of file configuration.cpp.

◆ ConfigParser() [4/4]

bitpit::ConfigParser::ConfigParser ( const std::string & rootName,
int version,
bool multiSections )

Construct a new configuration parser.

Parameters
rootNameis the name of the root element
versionis the required version
multiSectionsif set to true the configuration parser will allow multiple sections with the same name

Definition at line 93 of file configuration.cpp.

Member Function Documentation

◆ read() [1/2]

void bitpit::ConfigParser::read ( config::SourceFormat format,
const std::string & content,
bool append = true )

Read the specified content.

Configuration can be read from a content either in XML or JSON format.

Parameters
formatis the format of the content
contentis the content that will be read
appendcontrols if the configuration file will be appended to the current configuration or if the current configuration will be overwritten with the contents of the configuration file.

Definition at line 204 of file configuration.cpp.

◆ read() [2/2]

void bitpit::ConfigParser::read ( const std::string & filename,
bool append = true )

Read the specified configuration file.

Configuration can be read either from XML or JSON files.

Parameters
filenameis the filename of the configuration file
appendcontrols if the configuration file will be appended to the current configuration or if the current configuration will be overwritten with the contents of the configuration file.

Definition at line 161 of file configuration.cpp.

◆ reset() [1/3]

void bitpit::ConfigParser::reset ( const std::string & rootName)

Resets the configuration parser.

MultiSection property set in construction is not affected.

Parameters
rootNameis the name of the root element

Definition at line 106 of file configuration.cpp.

◆ reset() [2/3]

void bitpit::ConfigParser::reset ( const std::string & rootName,
int version )

Resets the configuration parser. MultiSections property set in construction is not affected.

Parameters
rootNameis the name of the root element
versionis the version

Definition at line 122 of file configuration.cpp.

◆ reset() [3/3]

void bitpit::ConfigParser::reset ( const std::string & rootName,
int version,
bool multiSections )

Resets the configuration parser. MultiSections property set in construction is forced to the new value given by the parameter multiSection

Parameters
rootNameis the name of the root element
versionis the version
multiSectionsif set to true the configuration parser will allow multiple sections with the same name

Definition at line 140 of file configuration.cpp.

◆ write() [1/2]

void bitpit::ConfigParser::write ( config::SourceFormat format,
std::string * content ) const

Write the configuration to the specified string.

Configuration can be written either in XML or JSON format.

Parameters
formatis the format that will be used to write the configuration
contenton output will contain the configuration in the specified format

Definition at line 259 of file configuration.cpp.

◆ write() [2/2]

void bitpit::ConfigParser::write ( const std::string & filename) const

Write the configuration to the specified file.

Configuration can be written either to XML or JSON files.

Parameters
filenameis the filename where the configuration will be written to

Definition at line 229 of file configuration.cpp.


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