libzypp  15.28.6
IniDict.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_PARSER_INIDICT_H
13 #define ZYPP_PARSER_INIDICT_H
14 
15 #include <iosfwd>
16 #include <map>
17 #include <string>
18 
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/base/InputStream.h"
21 #include "zypp/base/Iterator.h"
22 #include "zypp/parser/IniParser.h"
23 
25 namespace zypp
26 {
27  namespace parser
29  {
30 
32  //
33  // CLASS NAME : IniDict
34  //
40  class IniDict : public IniParser
41  {
42  friend std::ostream & operator<<( std::ostream & str, const IniDict & obj );
43  public:
44  typedef std::map<std::string, std::string> EntrySet;
45  typedef std::map<std::string, EntrySet> SectionSet;
47  typedef EntrySet::const_iterator entry_const_iterator;
48 
65 
80  entry_const_iterator entriesBegin(const std::string &section) const;
81  entry_const_iterator entriesEnd(const std::string &section) const;
83 
88  IniDict( const InputStream &is,
90 
94  IniDict();
95 
97  ~IniDict();
98 
103  void read( const InputStream &is,
105 
112  void insertEntry( const std::string &section,
113  const std::string &key,
114  const std::string &value );
115 
122  void deleteSection( const std::string &section );
123 
128  bool hasSection( const std::string &section ) const;
129 
138  bool hasEntry( const std::string &section,
139  const std::string &entry ) const;
140  public:
141 
143  virtual void consume( const std::string &section );
145  virtual void consume( const std::string &section,
146  const std::string &key,
147  const std::string &value );
148 
149  private:
157  };
159 
161  std::ostream & operator<<( std::ostream & str, const IniDict & obj );
162 
164  } // namespace parser
167 } // namespace zypp
169 #endif // ZYPP_PARSER_INIDICT_H
std::map< std::string, std::string > EntrySet
Definition: IniDict.h:44
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
Definition: IniDict.h:46
EntrySet _empty_map
empty map used to simulate iteration in non existant sections
Definition: IniDict.h:156
void deleteSection(const std::string &section)
add an entry
Definition: IniDict.cc:111
virtual void consume(const std::string &section)
Called when a section is found.
Definition: IniDict.cc:60
SectionSet _dict
Definition: IniDict.h:150
IniDict()
Creates a mepty dictionary.
Definition: IniDict.cc:42
std::ostream & operator<<(std::ostream &str, const IniDict &obj)
Definition: IniDict.cc:143
Helper to create and pass std::istream.
Definition: InputStream.h:56
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
void read(const InputStream &is, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Fill a dictionary from a InputStream containing a ini structured file.
Definition: IniDict.cc:46
void insertEntry(const std::string &section, const std::string &key, const std::string &value)
add an entry
Definition: IniDict.cc:104
section_const_iterator sectionsBegin() const
Definition: IniDict.cc:94
Simple INI-file parser.
Definition: IniParser.h:41
entry_const_iterator entriesEnd(const std::string &section) const
Definition: IniDict.cc:82
std::map< std::string, EntrySet > SectionSet
Definition: IniDict.h:45
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
Definition: Iterator.h:218
Parses a INI file and offers its structure as a dictionary.
Definition: IniDict.h:40
entry_const_iterator entriesBegin(const std::string &section) const
Definition: IniDict.cc:71
friend std::ostream & operator<<(std::ostream &str, const IniDict &obj)
Definition: IniDict.cc:143
EntrySet::const_iterator entry_const_iterator
Definition: IniDict.h:47
bool hasEntry(const std::string &section, const std::string &entry) const
True if an entry exists in the section.
Definition: IniDict.cc:124
bool hasSection(const std::string &section) const
True if there is a section with that name.
Definition: IniDict.cc:116
section_const_iterator sectionsEnd() const
Definition: IniDict.cc:99