1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/IniDict.cc
13 #include <zypp/base/Logger.h>
16 #include <zypp/parser/IniDict.h>
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : IniDict
30 ///////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // METHOD NAME : IniDict::IniDict
37 IniDict::IniDict( const InputStream &is,
38 const ProgressData::ReceiverFnc & progress )
47 void IniDict::read( const InputStream &is,
48 const ProgressData::ReceiverFnc & progress )
53 ///////////////////////////////////////////////////////////////////
55 // METHOD NAME : IniDict::~IniDict
61 void IniDict::consume( const std::string §ion )
63 _dict[section]; // remember even empty sections
66 void IniDict::consume( const std::string §ion, const std::string &key, const std::string &value )
68 _dict[section][key] = value;
72 IniDict::entry_const_iterator IniDict::entriesBegin(const std::string §ion) const
74 SectionSet::const_iterator secit = _dict.find(section);
75 if ( secit == _dict.end() )
77 return _empty_map.begin();
80 return (secit->second).begin();
83 IniDict::entry_const_iterator IniDict::entriesEnd(const std::string §ion) const
85 SectionSet::const_iterator secit = _dict.find(section);
86 if ( secit == _dict.end() )
88 return _empty_map.end();
91 return (secit->second).end();
94 Iterable<IniDict::entry_const_iterator> IniDict::entries(const std::string §ion) const
96 SectionSet::const_iterator secit = _dict.find(section);
97 if ( secit == _dict.end() )
99 return makeIterable( _empty_map.begin(), _empty_map.end() );
102 return makeIterable( (secit->second).begin(), (secit->second).end() );
105 IniDict::section_const_iterator IniDict::sectionsBegin() const
107 return make_map_key_begin( _dict );
110 IniDict::section_const_iterator IniDict::sectionsEnd() const
112 return make_map_key_end( _dict );
115 Iterable<IniDict::section_const_iterator> IniDict::sections() const
117 return makeIterable( sectionsBegin(), sectionsEnd() );
120 void IniDict::insertEntry( const std::string §ion,
121 const std::string &key,
122 const std::string &value )
124 consume( section, key, value );
128 void IniDict::deleteSection( const std::string §ion )
130 _dict.erase(section);
133 bool IniDict::hasSection( const std::string §ion ) const
135 SectionSet::const_iterator secit = _dict.find(section);
136 if ( secit == _dict.end() )
141 bool IniDict::hasEntry( const std::string §ion,
142 const std::string &entry ) const
144 SectionSet::const_iterator secit = _dict.find(section);
145 if ( secit == _dict.end() )
148 EntrySet::const_iterator entryit = (secit->second).find(entry);
149 if ( entryit == (secit->second).end() )
155 /******************************************************************
157 ** FUNCTION NAME : operator<<
158 ** FUNCTION TYPE : std::ostream &
160 std::ostream & operator<<( std::ostream & str, const IniDict & obj )
162 for ( IniDict::section_const_iterator si = obj.sectionsBegin();
163 si != obj.sectionsEnd();
166 str << "[" << *si << "]" << endl;
167 for ( IniDict::entry_const_iterator ei = obj.entriesBegin(*si);
168 ei != obj.entriesEnd(*si);
171 str << ei->first << " = " << ei->second << endl;
178 /////////////////////////////////////////////////////////////////
179 } // namespace parser
180 ///////////////////////////////////////////////////////////////////
181 /////////////////////////////////////////////////////////////////
183 ///////////////////////////////////////////////////////////////////