libzypp: zypp-core/parser/inidict.h Source File

libzypp 17.38.14

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-core/base/PtrTypes.h>
20#include <zypp-core/base/InputStream>
21#include <zypp-core/base/Iterator.h>
22#include <zypp-core/base/Iterable.h>
23#include <zypp-core/parser/IniParser>
24
26namespace zypp
27{
29 namespace parser
30 {
31
33 //
34 // CLASS NAME : IniDict
35 //
41 class ZYPP_API IniDict : public IniParser
42 {
43 friend std::ostream & operator<<( std::ostream & str, const IniDict & obj );
44 public:
45 using EntrySet = std::map<std::string, std::string>;
46 using SectionSet = std::map<std::string, EntrySet>;
47 using section_const_iterator = MapKVIteratorTraits<SectionSet>::Key_const_iterator;
48 using entry_const_iterator = EntrySet::const_iterator;
49
63 section_const_iterator sectionsBegin() const;
64 section_const_iterator sectionsEnd() const;
65 Iterable<section_const_iterator> sections() const;
67
80
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
105 IniDict( IniDict && ) = default;
106 IniDict & operator=( IniDict && ) = default;
107
109 ~IniDict() override;
110
115 void read( const InputStream &is,
116 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
117
124 void insertEntry( const std::string &section,
125 const std::string &key,
126 const std::string &value );
127
134 void deleteSection( const std::string &section );
135
140 bool hasSection( const std::string &section ) const;
141
150 bool hasEntry( const std::string &section,
151 const std::string &entry ) const;
152 public:
153
155 void consume( const std::string &section ) override;
157 void consume( const std::string &section,
158 const std::string &key,
159 const std::string &value ) override;
160
161 public:
163 std::ostream & dumpAsIniOn( std::ostream & str ) const;
164
165 private:
166 SectionSet _dict;
172 EntrySet _empty_map;
173 };
174
175
177 std::ostream & operator<<( std::ostream & str, const IniDict & obj );
178
180 inline std::ostream & dumpOn( std::ostream & str, const IniDict & obj )
181 { return obj.dumpAsIniOn( str ); }
182
184 } // namespace parser
187} // namespace zypp
189#endif // ZYPP_PARSER_INIDICT_H
ZYPP_API
#define ZYPP_API
Definition Globals.h:69
Iterable.h
Iterator.h
PtrTypes.h
IniDict::operator<<
friend std::ostream & operator<<(std::ostream &str, const IniDict &obj)
relates: IniDict Stream output
Definition inidict.cc:171
IniDict::IniDict
IniDict(const InputStream &is, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Creates a dictionary from a InputStream containing a ini structured file.
Definition inidict.cc:40
IniDict::IniDict
IniDict()
Creates an empty dictionary.
Definition inidict.cc:46
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:140
zypp::parser::IniDict
Parses a INI file and offers its structure as a dictionary.
Definition inidict.h:42
zypp::parser::IniDict::IniDict
IniDict(IniDict &&)=default
Move CTor.
zypp::parser::IniDict::sectionsEnd
section_const_iterator sectionsEnd() const
Definition inidict.cc:113
zypp::parser::IniDict::SectionSet
std::map< std::string, EntrySet > SectionSet
Definition inidict.h:46
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:50
zypp::parser::IniDict::hasSection
bool hasSection(const std::string &section) const
True if there is a section with that name.
Definition inidict.cc:136
zypp::parser::IniDict::deleteSection
void deleteSection(const std::string &section)
add an entry
Definition inidict.cc:131
zypp::parser::IniDict::operator=
IniDict & operator=(IniDict &&)=default
zypp::parser::IniDict::IniDict
IniDict(const InputStream &is, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Creates a dictionary from a InputStream containing a ini structured file.
Definition inidict.cc:40
zypp::parser::IniDict::sections
Iterable< section_const_iterator > sections() const
Definition inidict.cc:118
zypp::parser::IniDict::entriesBegin
entry_const_iterator entriesBegin(const std::string &section) const
Definition inidict.cc:75
zypp::parser::IniDict::entries
Iterable< entry_const_iterator > entries(const std::string &section) const
Definition inidict.cc:97
zypp::parser::IniDict::insertEntry
void insertEntry(const std::string &section, const std::string &key, const std::string &value)
add an entry
Definition inidict.cc:123
zypp::parser::IniDict::consume
void consume(const std::string &section) override
Called when a section is found.
Definition inidict.cc:64
zypp::parser::IniDict::EntrySet
std::map< std::string, std::string > EntrySet
Definition inidict.h:45
zypp::parser::IniDict::sectionsBegin
section_const_iterator sectionsBegin() const
Definition inidict.cc:108
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:144
zypp::parser::IniDict::_dict
SectionSet _dict
Definition inidict.h:166
zypp::parser::IniDict::dumpAsIniOn
std::ostream & dumpAsIniOn(std::ostream &str) const
Dump the collected iniMap as ini-file.
Definition inidict.cc:158
zypp::parser::IniDict::_empty_map
EntrySet _empty_map
empty map used to simulate iteration in non-existent sections
Definition inidict.h:172
zypp::parser::IniDict::section_const_iterator
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
Definition inidict.h:47
zypp::parser::IniDict::entry_const_iterator
EntrySet::const_iterator entry_const_iterator
Definition inidict.h:48
zypp::parser::IniDict::entriesEnd
entry_const_iterator entriesEnd(const std::string &section) const
Definition inidict.cc:86
zypp::parser::IniParser::IniParser
IniParser()
Default ctor.
Definition iniparser.cc:48
str
String related utilities and Regular expression matching.
zypp::parser
Definition HistoryLogReader.cc:30
zypp::parser::dumpOn
std::ostream & dumpOn(std::ostream &str, const IniDict &obj)
relates: IniDict Dump as single ini-file.
Definition inidict.h:180
zypp::parser::operator<<
std::ostream & operator<<(std::ostream &str, const ProductFileData &obj)
relates: ProductFileData Stream output
Definition ProductFileReader.cc:107
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:217