1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/IniDict.h
12 #ifndef ZYPP_PARSER_INIDICT_H
13 #define ZYPP_PARSER_INIDICT_H
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/base/InputStream.h>
21 #include <zypp/base/Iterator.h>
22 #include <zypp/base/Iterable.h>
23 #include <zypp/parser/IniParser.h>
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : IniDict
37 * Parses a INI file and offers its structure as a
41 class IniDict : public IniParser
43 friend std::ostream & operator<<( std::ostream & str, const IniDict & obj );
45 typedef std::map<std::string, std::string> EntrySet;
46 typedef std::map<std::string, EntrySet> SectionSet;
47 typedef MapKVIteratorTraits<SectionSet>::Key_const_iterator section_const_iterator;
48 typedef EntrySet::const_iterator entry_const_iterator;
51 * \name Section Iterators
52 * Iterate trough ini file sections
54 * for ( IniDict::section_const_iterator it = dict.sectionsBegin();
55 * it != dict.sectionsEnd();
58 * MIL << (*it) << endl;
63 section_const_iterator sectionsBegin() const;
64 section_const_iterator sectionsEnd() const;
65 Iterable<section_const_iterator> sections() const;
69 * \name Entries Iterators
70 * Iterate trough ini file entries in a section
72 * for ( IniDict::entry_const_iterator it = dict.entriesBegin("updates");
73 * it != dict.entriesEnd("updates");
76 * MIL << (*it).first << endl;
82 entry_const_iterator entriesBegin(const std::string §ion) const;
83 entry_const_iterator entriesEnd(const std::string §ion) const;
84 Iterable<entry_const_iterator> entries(const std::string §ion) const;
88 * Creates a dictionary from a InputStream
89 * containing a ini structured file
91 IniDict( const InputStream &is,
92 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
95 * Creates a mepty dictionary
103 * Fill a dictionary from a InputStream
104 * containing a ini structured file
106 void read( const InputStream &is,
107 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
110 * \short add an entry
115 void insertEntry( const std::string §ion,
116 const std::string &key,
117 const std::string &value );
120 * \short add an entry
125 void deleteSection( const std::string §ion );
128 * \short True if there is a section with that name
129 * \param section Section Name
131 bool hasSection( const std::string §ion ) const;
134 * \short True if an entry exists in the section
135 * \param section Section name
136 * \param entry entry name
138 * \note If the given section does not exist, this will
139 * of course return false.
141 bool hasEntry( const std::string §ion,
142 const std::string &entry ) const;
145 /** Called when a section is found. */
146 virtual void consume( const std::string §ion );
147 /** Called when a key value is found. */
148 virtual void consume( const std::string §ion,
149 const std::string &key,
150 const std::string &value );
155 * empty map used to simulate
156 * iteration in non existant
161 ///////////////////////////////////////////////////////////////////
163 /** \relates IniDict Stream output */
164 std::ostream & operator<<( std::ostream & str, const IniDict & obj );
166 /////////////////////////////////////////////////////////////////
167 } // namespace parser
168 ///////////////////////////////////////////////////////////////////
169 /////////////////////////////////////////////////////////////////
171 ///////////////////////////////////////////////////////////////////
172 #endif // ZYPP_PARSER_INIDICT_H