libassa
3.5.1
|
#include <IniFile.h>
Public Types | |
typedef pair< string, string > | tuple_type |
A tuple is a name/value pair. More... | |
typedef pair< string, list < tuple_type > > | sect_type |
A section is a logical subcategory of related configuration information. More... | |
typedef list< sect_type > | config_type |
INI configuration is the collection of sections. More... | |
typedef config_type::iterator | config_iterator |
Mutable iterator over the list of configuration sections. More... | |
typedef config_type::const_iterator | const_config_iterator |
Constant iterator over the list of configuration sections. More... | |
typedef list< tuple_type > ::iterator | tuple_iterator |
Mutable iterator over name/value pairs in a section. More... | |
typedef list< tuple_type > ::const_iterator | const_tuple_iterator |
Constant iterator over name/value pairs in a section. More... | |
Public Member Functions | |
IniFile (const string &fname_) | |
Do-nothing constructor. More... | |
~IniFile () | |
Destructor does not save cache data to the file. More... | |
bool | operator== (const IniFile &rhs_) const |
Compare two configurations. More... | |
bool | operator!= (const IniFile &rhs_) const |
Compare two configurations. More... | |
int | load () |
Load configuration data from the file. More... | |
void | drop_all () |
Clear up configuration cache. More... | |
int | sync () |
Write cached configuration to the file. More... | |
int | sync (const string &fname_) |
Write cached configuration to the file fname_. More... | |
void | add_section (const string §ion_) |
Add new section. More... | |
int | drop_section (const string §ion_) |
Remove section from cache. More... | |
int | set_pair (const string §ion_, const tuple_type &newkey_) |
Add or change name/value pair in the section. More... | |
int | drop_pair (const string §ion_, const string &name_) |
Remove name/value pair from the section in cache. More... | |
string | get_value (const string §ion_, const string &name_) const |
Find and return a value of the name/value pair in the section section_. More... | |
config_iterator | find_section (const string §ion_) |
Find section by its name. More... | |
const_config_iterator | find_section (const string §ion_) const |
Find section by its name. More... | |
const_config_iterator | sect_begin () const |
Return iterator to the first section. More... | |
config_iterator | sect_end () |
Return iterator past the last section. More... | |
unsigned int | size () const |
Return number of sections in the cache. More... | |
void | dump () const |
Dump cache to the log file. More... | |
Private Member Functions | |
int | trim_section_name (string &text_) |
Remove square brakets around section name. More... | |
Private Attributes | |
string | m_fname |
INI file name. More... | |
std::fstream | m_stream |
File stream. More... | |
config_type | m_config |
Cache holds the entire INI file in memory. More... | |
Regexp | m_section_pttrn |
Section header match. More... | |
Regexp | m_tuple_pttrn |
Name/value pair match. More... | |
Regexp | m_comment_pttrn |
Comment match. More... | |
typedef config_type::iterator ASSA::IniFile::config_iterator |
typedef list<sect_type> ASSA::IniFile::config_type |
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 23 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 34 of file IniFile.cpp.
References ASSA::INIFILE, m_config, and trace_with_mask.
void IniFile::add_section | ( | const string & | section_ | ) |
Add new section.
section_ | Section name to add |
Definition at line 189 of file IniFile.cpp.
References find_section(), and m_config.
|
inline |
Clear up configuration cache.
Definition at line 100 of file IniFile.h.
References m_config.
int IniFile::drop_pair | ( | const string & | section_, |
const string & | name_ | ||
) |
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 267 of file IniFile.cpp.
References DL, find_section(), ASSA::INIFILE, sect_end(), and trace_with_mask.
int IniFile::drop_section | ( | const string & | section_ | ) |
Remove section from cache.
section_ | Section to remove |
Definition at line 252 of file IniFile.cpp.
References DL, find_section(), ASSA::INIFILE, m_config, sect_end(), and trace_with_mask.
void IniFile::dump | ( | void | ) | const |
Dump cache to the log file.
Definition at line 141 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 199 of file IniFile.cpp.
References m_config.
Referenced by add_section(), drop_pair(), drop_section(), ASSA::CmdLineOpts::parse_config_file(), 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 214 of file IniFile.cpp.
References m_config.
string IniFile::get_value | ( | const string & | section_, |
const string & | name_ | ||
) | const |
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 165 of file IniFile.cpp.
References m_config.
Referenced by ASSA::CmdLineOpts::parse_config_file().
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 42 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 |
Compare two configurations.
Definition at line 82 of file IniFile.h.
References m_config.
|
inline |
Return iterator to the first section.
Definition at line 170 of file IniFile.h.
References m_config.
|
inline |
Return iterator past the last section.
Definition at line 174 of file IniFile.h.
References m_config.
Referenced by drop_pair(), drop_section(), ASSA::CmdLineOpts::parse_config_file(), 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 229 of file IniFile.cpp.
References DL, find_section(), ASSA::INIFILE, sect_end(), and trace_with_mask.
|
inline |
Return number of sections in the cache.
Definition at line 178 of file IniFile.h.
References m_config.
Referenced by load().
|
inline |
Write cached configuration to the file.
Filename used is the one given in the constructor.
Definition at line 219 of file IniFile.h.
References ASSA::INIFILE, m_fname, and trace_with_mask.
int IniFile::sync | ( | const string & | fname_ | ) |
Write cached configuration to the file fname_.
fname_ | Name of the output file. |
Definition at line 110 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 212 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(), get_value(), load(), operator==(), sect_begin(), sect_end(), size(), sync(), and ~IniFile().
|
private |
|
private |
|
private |
|
private |