libzypp 17.37.17
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>
15#include <boost/iterator/iterator_adaptor.hpp>
17
18namespace zyppng {
19
21 {
22 public:
23 using value_type = std::variant<std::monostate, std::string, int32_t, int64_t, bool>;
24
26
27 HeaderValue( const HeaderValue &other );
28 HeaderValue( HeaderValue &&other ) noexcept;
29
30 HeaderValue( const bool val );
31 HeaderValue( const int32_t val );
32 HeaderValue( const int64_t val );
33 HeaderValue( std::string &&val );
34 HeaderValue( const std::string &val );
35 HeaderValue( const char *val );
36
37 bool valid () const;
38
39 bool isString () const;
40 bool isInt () const;
41 bool isInt64 () const;
42 bool isDouble () const;
43 bool isBool () const;
44
45 const std::string &asString () const;
46 int32_t asInt () const;
47 int64_t asInt64 () const;
48 bool asBool () const;
49
51 const value_type &asVariant () const;
52
53 HeaderValue &operator= ( const HeaderValue &other );
54 HeaderValue &operator= ( HeaderValue &&other ) noexcept;
55 HeaderValue &operator= ( const std::string &val );
56 HeaderValue &operator= ( int32_t val );
57 HeaderValue &operator= ( int64_t val );
58 HeaderValue &operator= ( bool val );
59
60 bool operator== ( const HeaderValue &other ) const;
61
62 private:
64 };
65
67 {
68 public:
70 using ValueMap = std::map<std::string, std::vector<Value>>;
71
73
75 : public boost::iterator_adaptor<
76 HeaderValueMap::const_iterator // Derived
77 , ValueMap::const_iterator // Base
78 , std::pair<std::string, Value> // Value
79 , boost::use_default // CategoryOrTraversal
80 , const std::pair<const std::string&, const Value&> // Reference
81 >
82 {
83 public:
85 : const_iterator::iterator_adaptor_() {}
86
87 explicit const_iterator( const ValueMap::const_iterator &val )
88 { this->base_reference() = val; }
89
91 : const_iterator::iterator_adaptor_( other.base() ) {}
92
93 const std::string &key () const {
94 return this->base_reference()->first;
95 }
96
97 const Value &value() const {
98 auto &l = base_reference ()->second;
99 if ( l.empty() ) {
100 return InvalidValue;
101 }
102 return l.back();
103 }
104
105 private:
107 void increment() {
108 this->base_reference() = ++this->base_reference();
109 }
110
111 std::pair<const std::string&, const Value&> dereference() const
112 {
113 return std::pair<const std::string&, const Value&>( key(), value() );
114 }
115 };
116
117 HeaderValueMap() = default;
118 HeaderValueMap( std::initializer_list<ValueMap::value_type> init );
119
120 bool contains( const std::string &key ) const;
121 bool contains( const std::string_view &key ) const {
122 return contains(std::string(key));
123 }
124
125 void set( const std::string &key, Value val );
126 void set( const std::string &key, std::vector<Value> val );
127 void add( const std::string &key, const Value &val);
128 void clear ();
129 ValueMap::size_type size() const noexcept;
130
131 std::vector<Value> &values ( const std::string &key );
132 const std::vector<Value> &values ( const std::string &key ) const;
133
134 std::vector<Value> &values ( const std::string_view &key ) {
135 return values( std::string(key) );
136 }
137
138 const std::vector<Value> &values ( const std::string_view &key ) const {
139 return values( std::string(key) );
140 }
141
146 Value value ( const std::string_view &str, const Value &defaultVal = Value() ) const;
147 Value value ( const std::string &str, const Value &defaultVal = Value() ) const;
148
149 Value &operator[]( const std::string &key );
150 Value &operator[]( const std::string_view &key );
151 const Value &operator[]( const std::string &key ) const;
152 const Value &operator[]( const std::string_view &key ) const;
153
154 const_iterator erase( const const_iterator &i );
155 bool erase( const std::string &key );
156
158 return const_iterator( _values.begin() );
159 }
161 return const_iterator( _values.end() );
162 }
163
164 ValueMap::iterator beginList() {
165 return _values.begin();
166 }
167 ValueMap::iterator endList() {
168 return _values.end();
169 }
170
171 ValueMap::const_iterator beginList() const {
172 return _values.begin();
173 }
174 ValueMap::const_iterator endList() const {
175 return _values.end();
176 }
177
178 ValueMap::const_iterator cbeginList() const {
179 return _values.cbegin();
180 }
181 ValueMap::const_iterator cendList() const {
182 return _values.cend();
183 }
184
185 private:
187 };
188}
189
190namespace zypp {
191 template<>
194}
195
196
197#endif
const_iterator(const HeaderValueMap::const_iterator &other)
const_iterator(const ValueMap::const_iterator &val)
std::pair< const std::string &, const Value & > dereference() 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 Arch.h:364
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