inicpp
C++ parser of INI files with schema validation.
inicpp::config Class Reference

#include <config.h>

Public Types

using iterator = config_iterator< section >
 
using const_iterator = config_iterator< const section >
 

Public Member Functions

 config ()
 
 config (const config &source)
 
configoperator= (const config &source)
 
 config (config &&source)
 
configoperator= (config &&source)
 
void add_section (const section &sect)
 
void add_section (const std::string &section_name)
 
void remove_section (const std::string &section_name)
 
void add_option (const std::string &section_name, const option &opt)
 
template<typename ValueType >
void add_option (const std::string &section_name, const std::string &option_name, ValueType value)
 
void remove_option (const std::string &section_name, const std::string &option_name)
 
size_t size () const
 
sectionoperator[] (size_t index)
 
const sectionoperator[] (size_t index) const
 
sectionoperator[] (const std::string &section_name)
 
const sectionoperator[] (const std::string &section_name) const
 
bool contains (const std::string &section_name) const
 
void validate (const schema &schm, schema_mode mode)
 
bool operator== (const config &other) const
 
bool operator!= (const config &other) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Friends

class config_iterator< section >
 
class config_iterator< const section >
 
INICPP_API friend std::ostream & operator<< (std::ostream &os, const config &conf)
 

Detailed Description

Represents the base object of ini configuration. Contains list of sections in logical map structure. Can be constructed directly from string or stream.

Definition at line 28 of file config.h.

Member Typedef Documentation

type of const iterator

Definition at line 47 of file config.h.

type of iterator

Definition at line 45 of file config.h.

Constructor & Destructor Documentation

inicpp::config::config ( )

Default constructor.

Definition at line 5 of file config.cpp.

inicpp::config::config ( const config source)

Copy constructor.

Definition at line 9 of file config.cpp.

inicpp::config::config ( config &&  source)

Move constructor.

Definition at line 34 of file config.cpp.

Member Function Documentation

void inicpp::config::add_option ( const std::string &  section_name,
const option opt 
)

Add given option to specified section.

Parameters
section_nameshould exist
optoption which will be added to appropriate section
Exceptions
not_found_exceptionif section with given name does not exist
ambiguity_exceptionif option with specified name exists

Definition at line 89 of file config.cpp.

template<typename ValueType >
void inicpp::config::add_option ( const std::string &  section_name,
const std::string &  option_name,
ValueType  value 
)
inline

Creates and add option to specified section.

Parameters
section_nameshould exist in this config
option_namename of newly created option
valuevalue which will be stored in new option
Exceptions
ambiguity_exceptionif option with specified name exists

Definition at line 105 of file config.h.

void inicpp::config::add_section ( const section sect)

Add section to this ini configuration.

Parameters
sectsection which will be added
Exceptions
ambiguity_exceptionif section with specified name exists

Definition at line 48 of file config.cpp.

void inicpp::config::add_section ( const std::string &  section_name)

Create and add section with specified name.

Parameters
section_namesection with same name cannot exist in config
Exceptions
ambiguity_exceptionif section with specified name exists

Definition at line 60 of file config.cpp.

config::iterator inicpp::config::begin ( )

Iterator pointing at the beginning of sections list.

Returns
config_iterator

Definition at line 184 of file config.cpp.

config::const_iterator inicpp::config::begin ( ) const

Constant iterator pointing at the beginning of sections list.

Returns
config_iterator

Definition at line 194 of file config.cpp.

config::const_iterator inicpp::config::cbegin ( ) const

Constant iterator pointing at the beginning of sections list.

Returns
config_iterator

Definition at line 204 of file config.cpp.

config::const_iterator inicpp::config::cend ( ) const

Constant iterator pointing at the end of sections list.

Returns
config_iterator

Definition at line 209 of file config.cpp.

bool inicpp::config::contains ( const std::string &  section_name) const

Tries to find section with specified name inside this config.

Parameters
section_namename which is searched
Returns
true if section with this name is present, false otherwise

Definition at line 154 of file config.cpp.

config::iterator inicpp::config::end ( )

Iterator pointing at the end of sections list.

Returns
config_iterator

Definition at line 189 of file config.cpp.

config::const_iterator inicpp::config::end ( ) const

Constant iterator pointing at the end of sections list.

Returns
config_iterator

Definition at line 199 of file config.cpp.

bool inicpp::config::operator!= ( const config other) const

Inequality operator.

Parameters
other
Returns

Definition at line 179 of file config.cpp.

config & inicpp::config::operator= ( const config source)

Copy assignment.

Definition at line 23 of file config.cpp.

config & inicpp::config::operator= ( config &&  source)

Move assignment.

Definition at line 39 of file config.cpp.

bool inicpp::config::operator== ( const config other) const

Equality operator.

Parameters
other
Returns

Definition at line 169 of file config.cpp.

section & inicpp::config::operator[] ( size_t  index)

Access section on specified index.

Parameters
indexindex of requested value
Returns
modifiable reference to stored section
Exceptions
not_found_exceptionif index is out of range

Definition at line 114 of file config.cpp.

const section & inicpp::config::operator[] ( size_t  index) const

Access constant reference on section on specified index.

Parameters
indexindex of requested value
Returns
constant reference to stored section
Exceptions
not_found_exceptionif index is out of range

Definition at line 123 of file config.cpp.

section & inicpp::config::operator[] ( const std::string &  section_name)

Access section with specified name.

Parameters
section_namename of requested section
Returns
modifiable reference to stored section
Exceptions
not_found_exceptionif section with given name does not exist

Definition at line 132 of file config.cpp.

const section & inicpp::config::operator[] ( const std::string &  section_name) const

Access constant reference on section with specified name.

Parameters
section_namename of requested section
Returns
constant reference to stored section
Exceptions
not_found_exceptionif section with given name does not exist

Definition at line 143 of file config.cpp.

void inicpp::config::remove_option ( const std::string &  section_name,
const std::string &  option_name 
)

Removes option with given name from given section.

Parameters
section_nameindex to section list
option_nameoption with this name will be removed
Exceptions
not_found_exceptionif section or option with given name does not exist
not_found_exceptionif section or option with given name does not exist

Definition at line 99 of file config.cpp.

void inicpp::config::remove_section ( const std::string &  section_name)

Remove section from internal sections list.

Parameters
section_namename should exist in section list
Exceptions
not_found_exceptionif section with given name does not exist

Definition at line 72 of file config.cpp.

size_t inicpp::config::size ( ) const

Returns size of sections list

Returns
unsigned integer

Definition at line 109 of file config.cpp.

void inicpp::config::validate ( const schema schm,
schema_mode  mode 
)

Validates this config agains given schema.

Parameters
schmspecifies how this config should look like
modevalidation mode
Exceptions
validation_exceptionif error occured

Definition at line 164 of file config.cpp.

Friends And Related Function Documentation

INICPP_API friend std::ostream& operator<< ( std::ostream &  os,
const config conf 
)
friend

Classic stream operator for printing this instance to output stream.

Parameters
osoutput stream
confreference to loaded configuration
Returns
reference to output stream which allows chaining

Definition at line 214 of file config.cpp.


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