//MIL << dict["homedmacvicar"]["type"] << endl;
- for ( IniDict::const_iterator it = dict.begin(); it != dict.end(); ++it )
+ for ( IniDict::section_const_iterator it = dict.sectionsBegin(); it != dict.sectionsEnd(); ++it )
{
- MIL << (*it).first << endl;
+ MIL << (*it) << endl;
+
+ for ( IniDict::entry_const_iterator it2 = dict.entriesBegin(*it); it2 != dict.entriesEnd(*it); ++it2 )
+ {
+ MIL << " - " << (*it2).first << " | " << (*it2).second << endl;
+ }
}
}
void IniDict::consume( const std::string §ion, const std::string &key, const std::string &value )
{
//MIL << endl;
- PropertySet keys = _dict[section];
- keys[key] = value;
- _dict[section] = keys;
+ _dict[section][key] = value;
//MIL << this->size() << endl;
}
+ IniDict::entry_const_iterator IniDict::entriesBegin(const std::string §ion) const
+ {
+ SectionSet::const_iterator secit = _dict.find(section);
+ if ( secit == _dict.end() )
+ {
+ return _empty_map.begin();
+ }
+
+ return (secit->second).begin();
+ }
+
+ IniDict::entry_const_iterator IniDict::entriesEnd(const std::string §ion) const
+ {
+ SectionSet::const_iterator secit = _dict.find(section);
+ if ( secit == _dict.end() )
+ {
+ return _empty_map.end();
+ }
+
+ return (secit->second).end();
+ }
+
+
+ IniDict::section_const_iterator IniDict::sectionsBegin() const
+ {
+ return make_map_key_begin( _dict );
+ }
+
+ IniDict::section_const_iterator IniDict::sectionsEnd() const
+ {
+ return make_map_key_end( _dict );
+ }
+
/******************************************************************
**
** FUNCTION NAME : operator<<
#include "zypp/base/PtrTypes.h"
#include "zypp/base/InputStream.h"
+#include "zypp/base/Iterator.h"
#include "zypp/parser/IniParser.h"
///////////////////////////////////////////////////////////////////
{
friend std::ostream & operator<<( std::ostream & str, const IniDict & obj );
public:
- typedef std::map<std::string, std::string> PropertySet;
- typedef std::map<std::string, PropertySet> ConfigSet;
- typedef ConfigSet::const_iterator const_iterator;
+ typedef std::map<std::string, std::string> EntrySet;
+ typedef std::map<std::string, EntrySet> SectionSet;
+ typedef MapKVIteratorTraits<SectionSet>::Key_const_iterator section_const_iterator;
+ typedef EntrySet::const_iterator entry_const_iterator;
- const_iterator begin() const { return _dict.begin(); }
- const_iterator end() const { return _dict.end(); }
- /** Default ctor */
+ /**
+ * \name Section Iterators
+ * Iterate trough ini file sections
+ * \code
+ * for ( IniDict::section_const_iterator it = dict.sectionsBegin();
+ * it != dict.sectionsEnd();
+ * ++it )
+ * {
+ * MIL << (*it) << endl;
+ * }
+ * \endcode
+ */
+ //@{
+ section_const_iterator sectionsBegin() const;
+ section_const_iterator sectionsEnd() const;
+ //@}
+
+ /**
+ * \name Entries Iterators
+ * Iterate trough ini file entries in a section
+ * \code
+ * for ( IniDict::entry_const_iterator it = dict.entriesBegin("updates");
+ * it != dict.entriesEnd("updates");
+ * ++it )
+ * {
+ * MIL << (*it).first << endl;
+ * }
+ * \endcode
+ */
+
+ //@{
+ entry_const_iterator entriesBegin(const std::string §ion) const;
+ entry_const_iterator entriesEnd(const std::string §ion) const;
+ //@{
+
+ /**
+ * Creates a dictionary from a InputStream
+ * containing a ini structured file
+ */
IniDict( const InputStream &is );
+
/** Dtor */
~IniDict();
-
public:
/** Called when a section is found. */
virtual void consume( const std::string §ion, const std::string &key, const std::string &value );
private:
- ConfigSet _dict;
+ SectionSet _dict;
+
+ /**
+ * empty map used to simulate
+ * iteration in non existant
+ * sections
+ */
+ EntrySet _empty_map;
};
///////////////////////////////////////////////////////////////////
void IniParser::endParse()
{}
-void dumpRegexpResults( const boost::smatch &what )
-{
- for ( unsigned int k=0; k < what.size(); k++)
- {
- DBG << "[match "<< k << "] [" << what[k] << "]" << std::endl;
- }
-}
-
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : IniParser::parse
boost::smatch what;
if(boost::regex_match(trimmed, what, rxSection, boost::match_extra))
{
- //dumpRegexpResults(what);
+ //DBG << what << endl;
std::string section = what[1];
consume(section);
section.swap(_current_section);
boost::smatch what;
if(boost::regex_match(trimmed, what, rxKeyValue, boost::match_extra))
{
- //dumpRegexpResults(what);
+ //DBG << what << endl;
consume( _current_section, what[1], what[2] );
}
}