libzypp: zypp/parser/IniDict.h Source File

libzypp 17.25.10

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/base/Iterable.h>
23 #include <zypp/parser/IniParser.h>
24
26 namespace zypp
27 {
29 namespace parser
30 {
31
33 //
34 // CLASS NAME : IniDict
35 //
41 class IniDict : public IniParser
42 {
43 friend std::ostream & operator<<( std::ostream & str, const IniDict & obj );
44 public:
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;
49
63 section_const_iterator sectionsBegin() const;
64 section_const_iterator sectionsEnd() const;
65 Iterable<section_const_iterator> sections() const;
67
82 entry_const_iterator entriesBegin(const std::string &section) const;
83 entry_const_iterator entriesEnd(const std::string &section) const;
84 Iterable<entry_const_iterator> entries(const std::string &section) const;
86
91 IniDict( const InputStream &is,
92 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
93
97 IniDict();
98
100 ~IniDict();
101
106 void read( const InputStream &is,
107 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
108
115 void insertEntry( const std::string &section,
116 const std::string &key,
117 const std::string &value );
118
125 void deleteSection( const std::string &section );
126
131 bool hasSection( const std::string &section ) const;
132
141 bool hasEntry( const std::string &section,
142 const std::string &entry ) const;
143 public:
144
146 virtual void consume( const std::string &section );
148 virtual void consume( const std::string &section,
149 const std::string &key,
150 const std::string &value );
151
152 private:
153 SectionSet _dict;
159 EntrySet _empty_map;
160 };
162
164 std::ostream & operator<<( std::ostream & str, const IniDict & obj );
165
167 } // namespace parser
170 } // namespace zypp
172 #endif // ZYPP_PARSER_INIDICT_H
IniParser.h
InputStream.h
Iterable.h
Iterator.h
PtrTypes.h
zypp::InputStream
Helper to create and pass std::istream.
Definition: InputStream.h:57
zypp::Iterable
Definition: Iterable.h:37
zypp::ProgressData::ReceiverFnc
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
zypp::parser::IniDict
Parses a INI file and offers its structure as a dictionary.
Definition: IniDict.h:42
zypp::parser::IniDict::sectionsEnd
section_const_iterator sectionsEnd() const
Definition: IniDict.cc:110
zypp::parser::IniDict::~IniDict
~IniDict()
Dtor.
Definition: IniDict.cc:58
zypp::parser::IniDict::read
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:47
zypp::parser::IniDict::hasSection
bool hasSection(const std::string &section) const
True if there is a section with that name.
Definition: IniDict.cc:133
zypp::parser::IniDict::deleteSection
void deleteSection(const std::string &section)
add an entry
Definition: IniDict.cc:128
zypp::parser::IniDict::operator<<
friend std::ostream & operator<<(std::ostream &str, const IniDict &obj)
Definition: IniDict.cc:160
zypp::parser::IniDict::entry_const_iterator
EntrySet::const_iterator entry_const_iterator
Definition: IniDict.h:48
zypp::parser::IniDict::section_const_iterator
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
Definition: IniDict.h:47
zypp::parser::IniDict::sections
Iterable< section_const_iterator > sections() const
Definition: IniDict.cc:115
zypp::parser::IniDict::entriesBegin
entry_const_iterator entriesBegin(const std::string &section) const
Definition: IniDict.cc:72
zypp::parser::IniDict::entries
Iterable< entry_const_iterator > entries(const std::string &section) const
Definition: IniDict.cc:94
zypp::parser::IniDict::insertEntry
void insertEntry(const std::string &section, const std::string &key, const std::string &value)
add an entry
Definition: IniDict.cc:120
zypp::parser::IniDict::sectionsBegin
section_const_iterator sectionsBegin() const
Definition: IniDict.cc:105
zypp::parser::IniDict::hasEntry
bool hasEntry(const std::string &section, const std::string &entry) const
True if an entry exists in the section.
Definition: IniDict.cc:141
zypp::parser::IniDict::IniDict
IniDict()
Creates a mepty dictionary.
Definition: IniDict.cc:43
zypp::parser::IniDict::consume
virtual void consume(const std::string &section)
Called when a section is found.
Definition: IniDict.cc:61
zypp::parser::IniDict::_dict
SectionSet _dict
Definition: IniDict.h:153
zypp::parser::IniDict::_empty_map
EntrySet _empty_map
empty map used to simulate iteration in non existant sections
Definition: IniDict.h:159
zypp::parser::IniDict::EntrySet
std::map< std::string, std::string > EntrySet
Definition: IniDict.h:45
zypp::parser::IniDict::entriesEnd
entry_const_iterator entriesEnd(const std::string &section) const
Definition: IniDict.cc:83
zypp::parser::IniDict::SectionSet
std::map< std::string, EntrySet > SectionSet
Definition: IniDict.h:46
zypp::parser::IniParser
Simple INI-file parser.
Definition: IniParser.h:42
str
String related utilities and Regular expression matching.
zypp::parser::operator<<
std::ostream & operator<<(std::ostream &str, const IniDict &obj)
Definition: IniDict.cc:160
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::MapKVIteratorTraits::Key_const_iterator
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
Definition: Iterator.h:218