A class to get the content of a configuration file. More...
#include <configuration_file.hpp>
Classes | |
class | const_field_iterator |
This class is an iterator on the values set for a same field name. More... | |
struct | syntax_description |
This class tells us how to parse the input file. More... | |
Public Types | |
typedef claw::wrapped_iterator< constfile_content::key_type, file_content::const_iterator, const_pair_first< file_content::value_type > >::iterator_type | const_file_iterator |
Iterator on the name of the sections. | |
typedef claw::wrapped_iterator< constsection_content::key_type, section_content::const_iterator, const_pair_first< section_content::value_type > >::iterator_type | const_section_iterator |
Iterator on the fields of a section. | |
Public Member Functions | |
configuration_file () | |
Default constructor. | |
configuration_file (std::istream &is, const syntax_description &syntax=syntax_description()) | |
Constructor. | |
bool | open (std::istream &is, const syntax_description &syntax=syntax_description()) |
Read the configuration from a stream. | |
void | save (std::ostream &os, const syntax_description &syntax=syntax_description()) |
Write the configuration in a stream. | |
const std::string & | operator() (const std::string §ion, const std::string &field) const |
Get the value of a field. | |
const std::string & | operator() (const std::string &field) const |
Get the value of a field. | |
bool | has_field (const std::string §ion, const std::string &field) const |
Tell if a field exists. | |
bool | has_field (const std::string &field) const |
Tell if a field exists. | |
void | set_value (const std::string §ion, const std::string &field, const std::string &val) |
Set the value of a field. | |
void | set_value (const std::string &field, const std::string &val) |
Set the value of a field. | |
void | add_value (const std::string §ion, const std::string &field, const std::string &val) |
Add a value to a field. | |
void | add_value (const std::string &field, const std::string &val) |
Set the value of a field. | |
void | clear_section (const std::string §ion) |
Remove a section and its fields. | |
const_field_iterator | field_begin (const std::string §ion, const std::string &field) const |
Get an iterator on the first value set for a field. | |
const_field_iterator | field_end (const std::string §ion, const std::string &field) const |
Get an iterator past the last value set for a field. | |
const_field_iterator | field_begin (const std::string &field) const |
Get an iterator on the first value set for a field. | |
const_field_iterator | field_end (const std::string &field) const |
Get an iterator past the last value set for a field. | |
const_section_iterator | section_begin () const |
Get an iterator on the field names of a section. | |
const_section_iterator | section_end () const |
Get an iterator past the last field name of a section. | |
const_section_iterator | section_begin (const std::string §ion) const |
Get an iterator on the field names of a section. | |
const_section_iterator | section_end (const std::string §ion) const |
Get an iterator past the last field name of a section. | |
const_file_iterator | file_begin () const |
Get an iterator on the first named section. | |
const_file_iterator | file_end () const |
Get an iterator just past the last named section. | |
A class to get the content of a configuration file.
Definition at line 46 of file configuration_file.hpp.
typedef claw::wrapped_iterator<constfile_content::key_type,file_content::const_iterator,const_pair_first<file_content::value_type>>::iterator_type claw::configuration_file::const_file_iterator |
Iterator on the name of the sections.
Definition at line 91 of file configuration_file.hpp.
typedef claw::wrapped_iterator<constsection_content::key_type,section_content::const_iterator,const_pair_first<section_content::value_type>>::iterator_type claw::configuration_file::const_section_iterator |
Iterator on the fields of a section.
Definition at line 97 of file configuration_file.hpp.
claw::configuration_file::configuration_file | ( | ) |
Default constructor.
Definition at line 81 of file configuration_file.cpp.
claw::configuration_file::configuration_file | ( | std::istream & | is, |
const syntax_description & | syntax = syntax_description() ) |
Constructor.
is | The stream to read from. |
syntax | Description of the file's syntax. |
Definition at line 91 of file configuration_file.cpp.
void claw::configuration_file::add_value | ( | const std::string & | field, |
const std::string & | val ) |
Set the value of a field.
field | The name of the field to Set. |
val | The value. |
This method keeps all previous values for the given field.
Definition at line 264 of file configuration_file.cpp.
void claw::configuration_file::add_value | ( | const std::string & | section, |
const std::string & | field, | ||
const std::string & | val ) |
Add a value to a field.
section | The name of the section containing the field. |
field | The name of the field to add. |
val | The value. |
This method keeps all previous values for the given field.
Definition at line 250 of file configuration_file.cpp.
void claw::configuration_file::clear_section | ( | const std::string & | section | ) |
Remove a section and its fields.
section | The name of the section to remove. |
Definition at line 274 of file configuration_file.cpp.
claw::configuration_file::const_field_iterator claw::configuration_file::field_begin | ( | const std::string & | field | ) | const |
Get an iterator on the first value set for a field.
field | The name of the field to get. |
Definition at line 320 of file configuration_file.cpp.
claw::configuration_file::const_field_iterator claw::configuration_file::field_begin | ( | const std::string & | section, |
const std::string & | field ) const |
Get an iterator on the first value set for a field.
section | The name of the section in which is the field. |
field | The name of the field to get. |
Definition at line 285 of file configuration_file.cpp.
claw::configuration_file::const_field_iterator claw::configuration_file::field_end | ( | const std::string & | field | ) | const |
Get an iterator past the last value set for a field.
field | The name of the field to get. |
Definition at line 332 of file configuration_file.cpp.
claw::configuration_file::const_field_iterator claw::configuration_file::field_end | ( | const std::string & | section, |
const std::string & | field ) const |
Get an iterator past the last value set for a field.
section | The name of the section in which is the field. |
field | The name of the field to get. |
Definition at line 302 of file configuration_file.cpp.
claw::configuration_file::const_file_iterator claw::configuration_file::file_begin | ( | ) | const |
Get an iterator on the first named section.
Definition at line 393 of file configuration_file.cpp.
claw::configuration_file::const_file_iterator claw::configuration_file::file_end | ( | ) | const |
Get an iterator just past the last named section.
Definition at line 402 of file configuration_file.cpp.
bool claw::configuration_file::has_field | ( | const std::string & | field | ) | const |
Tell if a field exists.
field | The name of the field to test. |
Definition at line 201 of file configuration_file.cpp.
bool claw::configuration_file::has_field | ( | const std::string & | section, |
const std::string & | field ) const |
Tell if a field exists.
section | The name of the section containing the field. |
field | The name of the field to test. |
Definition at line 189 of file configuration_file.cpp.
bool claw::configuration_file::open | ( | std::istream & | is, |
const syntax_description & | syntax = syntax_description() ) |
Read the configuration from a stream.
is | The stream to read from. |
syntax | Description of the file's syntax. |
Definition at line 102 of file configuration_file.cpp.
const std::string & claw::configuration_file::operator() | ( | const std::string & | field | ) | const |
Get the value of a field.
field | The name of the field to get. |
Definition at line 174 of file configuration_file.cpp.
const std::string & claw::configuration_file::operator() | ( | const std::string & | section, |
const std::string & | field ) const |
Get the value of a field.
section | The name of the section in which is the field. |
field | The name of the field to get. |
Definition at line 149 of file configuration_file.cpp.
void claw::configuration_file::save | ( | std::ostream & | os, |
const syntax_description & | syntax = syntax_description() ) |
Write the configuration in a stream.
os | The stream to write in. |
syntax | Description of the file's syntax. |
Definition at line 125 of file configuration_file.cpp.
claw::configuration_file::const_section_iterator claw::configuration_file::section_begin | ( | ) | const |
Get an iterator on the field names of a section.
Definition at line 343 of file configuration_file.cpp.
claw::configuration_file::const_section_iterator claw::configuration_file::section_begin | ( | const std::string & | section | ) | const |
Get an iterator on the field names of a section.
section | The name of the section in which the fields are searched. |
Definition at line 364 of file configuration_file.cpp.
claw::configuration_file::const_section_iterator claw::configuration_file::section_end | ( | ) | const |
Get an iterator past the last field name of a section.
Definition at line 354 of file configuration_file.cpp.
claw::configuration_file::const_section_iterator claw::configuration_file::section_end | ( | const std::string & | section | ) | const |
Get an iterator past the last field name of a section.
section | The name of the section in which the fields are searched. |
Definition at line 379 of file configuration_file.cpp.
void claw::configuration_file::set_value | ( | const std::string & | field, |
const std::string & | val ) |
Set the value of a field.
field | The name of the field to Set. |
val | The value. |
This method removes all previous values for the given field.
Definition at line 235 of file configuration_file.cpp.
void claw::configuration_file::set_value | ( | const std::string & | section, |
const std::string & | field, | ||
const std::string & | val ) |
Set the value of a field.
section | The name of the section containing the field. |
field | The name of the field to set. |
val | The value. |
This method removes all previous values for the given field.
Definition at line 214 of file configuration_file.cpp.