libzypp 17.37.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-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
26 namespace 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
100 ~IniDict() override;
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 void consume( const std::string &section ) override;
148 void consume( const std::string &section,
149 const std::string &key,
150 const std::string &value ) override;
151
152 private:
153 SectionSet _dict;
159 EntrySet _empty_map;
160 };
161
162
164 std::ostream & operator<<( std::ostream & str, const IniDict & obj ) ZYPP_API;
165
167 } // namespace parser
170} // namespace zypp
172#endif // ZYPP_PARSER_INIDICT_H
operator<<
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Definition LookupAttr.cc:808
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::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::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::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:153
zypp::parser::IniDict::_empty_map
EntrySet _empty_map
empty map used to simulate iteration in non-existent sections
Definition inidict.h:159
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::operator<<
std::ostream & operator<<(std::ostream &str, const ProductFileData &obj)
Definition ProductFileReader.cc:107
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
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
ZYPP_API
#define ZYPP_API
Definition Globals.h:69
Iterable.h
Iterator.h
PtrTypes.h