49 SectionTable::iterator
i = table.begin();
50 SectionTable::iterator end = table.end();
61 ifstream
f(file.c_str());
80 const std::string &value,
83 EntryTable::iterator ei = table.find(entryName);
85 if (ei == table.end()) {
87 table[entryName] =
new Entry(value);
91 ei->second->appendValue(value);
95 ei->second->setValue(value);
104 if (offset == string::npos) {
106 cerr <<
"Can't parse .ini line " << assignment << endl;
111 bool append = (assignment[offset-1] ==
'+');
113 string entryName = assignment.substr(0, append ? offset-1 : offset);
114 string value = assignment.substr(offset + 1);
119 addEntry(entryName, value, append);
129 EntryTable::const_iterator ei = table.find(entryName);
131 return (ei == table.end()) ? NULL : ei->second;
138 SectionTable::iterator
i = table.find(sectionName);
140 if (i != table.end()) {
146 table[sectionName] = sec;
155 SectionTable::const_iterator
i = table.find(sectionName);
157 return (i == table.end()) ? NULL : i->second;
168 if (offset == string::npos)
171 string sectionName = str.substr(0, offset);
172 string rest = str.substr(offset + 1);
175 Section *
s = addSection(sectionName);
183 Section *section = NULL;
193 if (line.size() == 0)
197 int last = line.size() - 1;
199 if (line[0] ==
'[' && line[last] ==
']') {
200 string sectionName = line.substr(1, last - 1);
202 section = addSection(sectionName);
209 if (!section->add(line))
220 Section *section = findSection(sectionName);
236 Section *section = findSection(sectionName);
247 return findSection(sectionName) != NULL;
255 bool search_unref_entries =
false;
258 Entry *entry = findEntry(
"unref_entries_ok");
261 if (unref_ok_entries.size()) {
262 search_unref_entries =
true;
266 for (EntryTable::iterator ei = table.begin();
267 ei != table.end(); ++ei) {
268 const string &entryName = ei->first;
271 if (entryName ==
"unref_section_ok" ||
272 entryName ==
"unref_entries_ok")
278 if (search_unref_entries &&
279 (std::find(unref_ok_entries.begin(), unref_ok_entries.end(),
280 entryName) != unref_ok_entries.end()))
285 cerr <<
"Parameter " << sectionName <<
":" << entryName
286 <<
" not referenced." << endl;
298 for (SectionTable::const_iterator
i = table.begin();
299 i != table.end(); ++
i)
301 list.push_back((*i).first);
310 for (SectionTable::iterator
i = table.begin();
311 i != table.end(); ++
i) {
312 const string §ionName =
i->first;
316 if (section->
findEntry(
"unref_section_ok") == NULL) {
317 cerr <<
"Section " << sectionName <<
" not referenced."
336 for (EntryTable::iterator ei = table.begin();
337 ei != table.end(); ++ei) {
338 cout << sectionName <<
": " << (*ei).first <<
" => "
339 << (*ei).second->getValue() <<
"\n";
346 for (SectionTable::iterator
i = table.begin();
347 i != table.end(); ++
i) {
348 i->second->dump(
i->first);
void getSectionNames(std::vector< std::string > &list) const
Push all section names into the given vector.
void eat_end_white(std::string &s)
bool printUnreferenced()
Print unreferenced entries in object.
Entry * findEntry(const std::string &entryName) const
Find the entry with the given name.
bool isReferenced()
Has this entry been used?
Section * addSection(const std::string §ionName)
Look up section with the given name, creating a new section if not found.
void dump(const std::string §ionName)
Print the contents of this section to cout (for debugging).
bool add(const std::string &s)
Take string of the form "<section>:<parameter>=<value>" or "<section>:<parameter>+=<value>" and add t...
bool printUnreferenced(const std::string §ionName)
Print the unreferenced entries in this section to cerr.
bool entryExists(const std::string §ion, const std::string &entry) const
Determine whether the entry exists within named section exists in the .ini file.
bool find(const std::string §ion, const std::string &entry, std::string &value) const
Find value corresponding to given section and entry names.
bool load(std::istream &f)
Load parameter settings from given istream.
Declaration of IniFile object.
const std::string & getValue() const
Fetch the value.
Section * findSection(const std::string §ionName) const
Look up section with the given name.
void eat_white(std::string &s)
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
bool isReferenced()
Has this section been used?
void dump()
Dump contents to cout. For debugging.
bool sectionExists(const std::string §ion) const
Determine whether the named section exists in the .ini file.
bool add(const std::string &assignment)
Add an entry to the table given a string assigment.
void addEntry(const std::string &entryName, const std::string &value, bool append)
Add an entry to the table.