libassa 3.5.1
|
#include <IniFile.h>
Public Types | |
typedef pair< string, string > | tuple_type |
A tuple is a name/value pair. | |
typedef pair< string, list< tuple_type > > | sect_type |
A section is a logical subcategory of related configuration information. | |
typedef list< sect_type > | config_type |
INI configuration is the collection of sections. | |
typedef config_type::iterator | config_iterator |
Mutable iterator over the list of configuration sections. | |
typedef config_type::const_iterator | const_config_iterator |
Constant iterator over the list of configuration sections. | |
typedef list< tuple_type >::iterator | tuple_iterator |
Mutable iterator over name/value pairs in a section. | |
typedef list< tuple_type >::const_iterator | const_tuple_iterator |
Constant iterator over name/value pairs in a section. | |
Public Member Functions | |
IniFile (const string &fname_) | |
Do-nothing constructor. | |
~IniFile () | |
Destructor does not save cache data to the file. | |
bool | operator== (const IniFile &rhs_) const |
Compare two configurations. | |
bool | operator!= (const IniFile &rhs_) const |
Compare two configurations. | |
int | load () |
Load configuration data from the file. | |
void | drop_all () |
Clear up configuration cache. | |
int | sync () |
Write cached configuration to the file. | |
int | sync (const string &fname_) |
Write cached configuration to the file fname_. | |
void | add_section (const string §ion_) |
Add new section. | |
int | drop_section (const string §ion_) |
Remove section from cache. | |
int | set_pair (const string §ion_, const tuple_type &newkey_) |
Add or change name/value pair in the section. | |
int | drop_pair (const string §ion_, const string &name_) |
Remove name/value pair from the section in cache. | |
string | get_value (const string §ion_, const string &name_) const |
Find and return a value of the name/value pair in the section section_. | |
config_iterator | find_section (const string §ion_) |
Find section by its name. | |
const_config_iterator | find_section (const string §ion_) const |
Find section by its name. | |
const_config_iterator | sect_begin () const |
Return iterator to the first section. | |
config_iterator | sect_end () |
Return iterator past the last section. | |
unsigned int | size () const |
Return number of sections in the cache. | |
void | dump () const |
Dump cache to the log file. | |
Private Member Functions | |
int | trim_section_name (string &text_) |
Remove square brakets around section name. | |
Private Attributes | |
string | m_fname |
INI file name. | |
std::fstream | m_stream |
File stream. | |
config_type | m_config |
Cache holds the entire INI file in memory. | |
Regexp | m_section_pttrn |
Section header match. | |
Regexp | m_tuple_pttrn |
Name/value pair match. | |
Regexp | m_comment_pttrn |
Comment match. | |
typedef config_type::iterator ASSA::IniFile::config_iterator |
typedef config_type::const_iterator ASSA::IniFile::const_config_iterator |
typedef list<tuple_type>::const_iterator ASSA::IniFile::const_tuple_iterator |
typedef pair<string, list<tuple_type> > ASSA::IniFile::sect_type |
typedef list<tuple_type>::iterator ASSA::IniFile::tuple_iterator |
typedef pair<string, string> ASSA::IniFile::tuple_type |
IniFile::IniFile | ( | const string & | fname_ | ) |
Do-nothing constructor.
fname_ | Name of the INI file |
Definition at line 22 of file IniFile.cpp.
References ASSA::INIFILE, and trace_with_mask.
IniFile::~IniFile | ( | ) |
Destructor does not save cache data to the file.
You should explicitly call sync() if you want your data to be saved to the file.
Definition at line 33 of file IniFile.cpp.
References ASSA::INIFILE, m_config, and trace_with_mask.
Add new section.
section_ | Section name to add |
Definition at line 188 of file IniFile.cpp.
References find_section(), and m_config.
|
inline |
Remove name/value pair from the section in cache.
section_ | Section that holds name/value pair. |
name_ | Name part of name/value pair. |
Definition at line 266 of file IniFile.cpp.
References DL, find_section(), ASSA::INIFILE, sect_end(), and trace_with_mask.
Remove section from cache.
section_ | Section to remove |
Definition at line 251 of file IniFile.cpp.
References DL, find_section(), ASSA::INIFILE, m_config, sect_end(), and trace_with_mask.
void IniFile::dump | ( | ) | const |
Dump cache to the log file.
Definition at line 140 of file IniFile.cpp.
References DL, ASSA::INIFILE, m_config, and trace_with_mask.
IniFile::config_iterator IniFile::find_section | ( | const string & | section_ | ) |
Find section by its name.
section_ | Section name to earch for |
Definition at line 198 of file IniFile.cpp.
References m_config.
Referenced by add_section(), drop_pair(), drop_section(), and set_pair().
IniFile::const_config_iterator IniFile::find_section | ( | const string & | section_ | ) | const |
Find section by its name.
section_ | Section name to earch for |
Definition at line 213 of file IniFile.cpp.
References m_config.
Find and return a value of the name/value pair in the section section_.
section_ | Section name to search for name/value |
name_ | Name part of name/value pair |
Definition at line 164 of file IniFile.cpp.
References m_config.
int IniFile::load | ( | ) |
Load configuration data from the file.
The file name is specified in the constructor.
From N.M.Josuttis, "The C++ Standard Library", Sec. 13.9 File Access:
"Clear eofbit and failbit set due to the end-of-file. Note that after the processing of a file, clear() must be called to clear the state flags that are set at end-of-file. This is required because the stream object is used for multiple files. open() NEVER clears any state flags. Thus, if a stream was not in a good state, after closing and reopening it, you still have to call clear() to get to a good state. This is also the case, if you open a different file."
Definition at line 41 of file IniFile.cpp.
References DL, ASSA::INIFILE, m_comment_pttrn, m_config, m_fname, m_section_pttrn, m_stream, m_tuple_pttrn, ASSA::Regexp::match(), size(), ASSA::Utils::split_pair(), trace_with_mask, trim_section_name(), and ASSA::Utils::trim_sides().
|
inline |
|
inline |
Return iterator past the last section.
Definition at line 174 of file IniFile.h.
References m_config.
Referenced by drop_pair(), drop_section(), and set_pair().
int IniFile::set_pair | ( | const string & | section_, |
const tuple_type & | newkey_ | ||
) |
Add or change name/value pair in the section.
section_ | Section name |
newkey_ | Name/value pair |
Definition at line 228 of file IniFile.cpp.
References DL, find_section(), ASSA::INIFILE, sect_end(), and trace_with_mask.
|
inline |
Write cached configuration to the file.
Filename used is the one given in the constructor.
Definition at line 218 of file IniFile.h.
References ASSA::INIFILE, m_fname, sync(), and trace_with_mask.
Referenced by sync().
Write cached configuration to the file fname_.
fname_ | Name of the output file. |
Definition at line 109 of file IniFile.cpp.
References EL, ASSA::INIFILE, m_config, m_stream, and trace_with_mask.
|
inlineprivate |
Remove square brakets around section name.
text_ | (IN/OUT) String to work on |
Definition at line 211 of file IniFile.h.
References ASSA::Utils::ltrim(), and ASSA::Utils::rtrim().
Referenced by load().
|
private |
|
private |
Cache holds the entire INI file in memory.
Definition at line 199 of file IniFile.h.
Referenced by add_section(), drop_all(), drop_section(), dump(), find_section(), find_section(), get_value(), load(), operator==(), sect_begin(), sect_end(), size(), sync(), and ~IniFile().
|
private |
|
private |
|
private |
|
private |