libzypp 17.38.7
headervaluemap.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_MEDIA_NG_HEADERVALUEMAP_H_INCLUDED
10#define ZYPP_MEDIA_NG_HEADERVALUEMAP_H_INCLUDED
11
12#include <variant>
13#include <string>
14#include <map>
16
17namespace zyppng {
18
20 {
21 public:
22 using value_type = std::variant<std::monostate, std::string, int32_t, int64_t, bool>;
23
25
26 HeaderValue( const HeaderValue &other );
27 HeaderValue( HeaderValue &&other ) noexcept;
28
29 HeaderValue( const bool val );
30 HeaderValue( const int32_t val );
31 HeaderValue( const int64_t val );
32 HeaderValue( std::string &&val );
33 HeaderValue( const std::string &val );
34 HeaderValue( const char *val );
35
36 bool valid () const;
37
38 bool isString () const;
39 bool isInt () const;
40 bool isInt64 () const;
41 bool isDouble () const;
42 bool isBool () const;
43
44 const std::string &asString () const;
45 int32_t asInt () const;
46 int64_t asInt64 () const;
47 bool asBool () const;
48
50 const value_type &asVariant () const;
51
52 HeaderValue &operator= ( const HeaderValue &other );
53 HeaderValue &operator= ( HeaderValue &&other ) noexcept;
54 HeaderValue &operator= ( const std::string &val );
55 HeaderValue &operator= ( int32_t val );
56 HeaderValue &operator= ( int64_t val );
57 HeaderValue &operator= ( bool val );
58
59 bool operator== ( const HeaderValue &other ) const;
60
61 private:
63 };
64
66 {
67 public:
69 using ValueMap = std::map<std::string, std::vector<Value>>;
70
72
74 {
75 public:
76 using iterator_category = std::forward_iterator_tag;
77 using value_type = std::pair<std::string, Value>;
78 using difference_type = std::ptrdiff_t;
79 using pointer = void;
80 using reference = const std::pair<const std::string&, const Value&>;
81
82 private:
83 ValueMap::const_iterator _it;
84
85 public:
86 const_iterator() = default;
87
88 explicit const_iterator( const ValueMap::const_iterator &val )
89 : _it(val) {}
90
92 : _it(other.base()) {}
93
94 const std::string &key () const {
95 return _it->first;
96 }
97
98 const Value &value() const {
99 auto &l = _it->second;
100 if ( l.empty() ) {
101 return InvalidValue;
102 }
103 return l.back();
104 }
105
107 return reference( key(), value() );
108 }
109
111 ++_it;
112 return *this;
113 }
114
116 const_iterator tmp = *this;
117 ++_it;
118 return tmp;
119 }
120
121 bool operator==(const const_iterator& other) const {
122 return _it == other._it;
123 }
124
125 bool operator!=(const const_iterator& other) const {
126 return !(*this == other);
127 }
128
129 const ValueMap::const_iterator& base() const { return _it; }
130 };
131
132 HeaderValueMap() = default;
133 HeaderValueMap( std::initializer_list<ValueMap::value_type> init );
134
135 bool contains( const std::string &key ) const;
136 bool contains( const std::string_view &key ) const {
137 return contains(std::string(key));
138 }
139
140 void set( const std::string &key, Value val );
141 void set( const std::string &key, std::vector<Value> val );
142 void add( const std::string &key, const Value &val);
143 void clear ();
144 ValueMap::size_type size() const noexcept;
145
146 std::vector<Value> &values ( const std::string &key );
147 const std::vector<Value> &values ( const std::string &key ) const;
148
149 std::vector<Value> &values ( const std::string_view &key ) {
150 return values( std::string(key) );
151 }
152
153 const std::vector<Value> &values ( const std::string_view &key ) const {
154 return values( std::string(key) );
155 }
156
161 Value value ( const std::string_view &str, const Value &defaultVal = Value() ) const;
162 Value value ( const std::string &str, const Value &defaultVal = Value() ) const;
163
164 Value &operator[]( const std::string &key );
165 Value &operator[]( const std::string_view &key );
166 const Value &operator[]( const std::string &key ) const;
167 const Value &operator[]( const std::string_view &key ) const;
168
169 const_iterator erase( const const_iterator &i );
170 bool erase( const std::string &key );
171
173 return const_iterator( _values.begin() );
174 }
176 return const_iterator( _values.end() );
177 }
178
179 ValueMap::iterator beginList() {
180 return _values.begin();
181 }
182 ValueMap::iterator endList() {
183 return _values.end();
184 }
185
186 ValueMap::const_iterator beginList() const {
187 return _values.begin();
188 }
189 ValueMap::const_iterator endList() const {
190 return _values.end();
191 }
192
193 ValueMap::const_iterator cbeginList() const {
194 return _values.cbegin();
195 }
196 ValueMap::const_iterator cendList() const {
197 return _values.cend();
198 }
199
200 private:
202 };
203}
204
205namespace zypp {
206 template<>
209}
210
211
212#endif
const_iterator(const HeaderValueMap::const_iterator &other)
const std::pair< const std::string &, const Value & > reference
std::forward_iterator_tag iterator_category
const_iterator(const ValueMap::const_iterator &val)
std::pair< std::string, Value > value_type
bool operator!=(const const_iterator &other) const
const ValueMap::const_iterator & base() const
bool operator==(const const_iterator &other) const
const std::string & key() const
HeaderValueMap(std::initializer_list< ValueMap::value_type > init)
void add(const std::string &key, const Value &val)
Value & operator[](const std::string &key)
const_iterator erase(const const_iterator &i)
std::map< std::string, std::vector< Value > > ValueMap
ValueMap::const_iterator beginList() const
ValueMap::const_iterator cendList() const
ValueMap::iterator beginList()
const std::vector< Value > & values(const std::string_view &key) const
Value value(const std::string_view &str, const Value &defaultVal=Value()) const
bool contains(const std::string &key) const
ValueMap::const_iterator endList() const
const_iterator begin() const
ValueMap::iterator endList()
ValueMap::size_type size() const noexcept
void set(const std::string &key, Value val)
bool contains(const std::string_view &key) const
std::vector< Value > & values(const std::string &key)
ValueMap::const_iterator cbeginList() const
const_iterator end() const
value_type & asVariant()
bool operator==(const HeaderValue &other) const
zypp::RWCOW_pointer< value_type > _val
HeaderValue & operator=(const HeaderValue &other)
int32_t asInt() const
std::variant< std::monostate, std::string, int32_t, int64_t, bool > value_type
const std::string & asString() const
bool isDouble() const
int64_t asInt64() const
Definition ansi.h:855
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
zyppng::HeaderValue::value_type * rwcowClone< zyppng::HeaderValue::value_type >(const zyppng::HeaderValue::value_type *rhs)
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469