26 m_section_pttrn (
"\\[[a-zA-Z0-9]+.*] *$"),
27 m_tuple_pttrn (
"^[ \t]*[a-zA-Z0-9]+.* *= *.*"),
28 m_comment_pttrn (
"^#.*$")
46 const int size = 1024;
101 DL((
INIFILE,
"Parse error: illegal syntax!\n"));
110 sync (
const string& fname_)
114 ::unlink (fname_.c_str ());
115 m_stream.open (fname_.c_str (), std::ios::app | std::ios::out);
117 EL((
INIFILE,
"Failed to open(\"%s\", app|out)\n", fname_.c_str ()));
124 m_stream <<
"[" << (*i).first <<
"]\n";
125 j = (*i).second.begin ();
127 while (j != (*i).second.end ()) {
128 m_stream << (*j).first <<
"=" << (*j).second <<
"\n";
148 DL((
INIFILE,
"============= Start =================\n"));
151 DL((
INIFILE,
"[%s]\n", (*i).first.c_str ()));
152 j = (*i).second.begin ();
153 while (j != (*i).second.end ()) {
155 (*j).first.c_str (), (*j).second.c_str ()));
160 DL((
INIFILE,
"============== End =================\n"));
165 get_value (
const string& section_,
const string& name_)
const
172 if ((*i).first == section_) {
173 j = (*i).second.begin ();
174 while (j != (*i).second.end ()) {
175 if ((*j).first == name_) {
204 if ((*i).first == section_) {
219 if ((*i).first == section_) {
229 set_pair (
const string& section_,
const tuple_type& newkey_)
235 DL((
INIFILE,
"Section [%s] is not found!\n", section_.c_str ()));
239 while (j != (*i).second.end ()) {
240 if ((*j).first == newkey_.first) {
241 (*j).second = newkey_.second;
246 (*i).second.push_back (newkey_);
258 DL((
INIFILE,
"Section [%s] is not found!\n", section_.c_str ()));
267 drop_pair (
const string& section_,
const string& name_)
273 DL((
INIFILE,
"Section [%s] is not found!\n", section_.c_str ()));
278 while (j != (*i).second.end ()) {
279 if ((*j).first == name_) {
280 (*i).second.erase (j);
A collection of assert function wrappers.
A Windows-style INI configuration file management class.
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Regexp m_tuple_pttrn
Name/value pair match.
std::fstream m_stream
File stream.
void add_section(const string §ion_)
Add new section.
int trim_section_name(string &text_)
Remove square brakets around section name.
pair< string, string > tuple_type
A tuple is a name/value pair.
config_type m_config
Cache holds the entire INI file in memory.
int load()
Load configuration data from the file.
config_type::iterator config_iterator
Mutable iterator over the list of configuration sections.
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.
config_type::const_iterator const_config_iterator
Constant iterator over the list of configuration sections.
config_iterator find_section(const string §ion_)
Find section by its name.
IniFile(const string &fname_)
Do-nothing constructor.
int drop_section(const string §ion_)
Remove section from cache.
Regexp m_comment_pttrn
Comment match.
Regexp m_section_pttrn
Section header match.
config_iterator sect_end()
Return iterator past the last section.
int sync()
Write cached configuration to the file.
list< tuple_type >::iterator tuple_iterator
Mutable iterator over name/value pairs in a section.
void dump() const
Dump cache to the log file.
string get_value(const string §ion_, const string &name_) const
Find and return a value of the name/value pair in the section section_.
unsigned int size() const
Return number of sections in the cache.
list< tuple_type >::const_iterator const_tuple_iterator
Constant iterator over name/value pairs in a section.
string m_fname
INI file name.
pair< string, list< tuple_type > > sect_type
A section is a logical subcategory of related configuration information.
int match(const char *text_)
Match an ASCII character string agains the pattern this class wraps.
int split_pair(const string &text_, char sep_, string &lhs_, string &rhs_)
Split input string into two parts separated by the separator character.
void trim_sides(std::string &text_)
Trim white spaces and tabs from the beginning and the end of the text string.
@ INIFILE
Class IniFile messages