libzypp
17.32.2
headervaluemap.cc
Go to the documentation of this file.
1
#include "
headervaluemap.h
"
2
#include <zypp-core/base/String.h>
3
4
namespace
zyppng
{
5
6
HeaderValueMap::Value
HeaderValueMap::InvalidValue
;
7
8
HeaderValue::HeaderValue
()
9
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>() )
10
{}
11
12
HeaderValue::HeaderValue
(
const
HeaderValue
&other )
13
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>( *other._val ) )
14
{}
15
16
HeaderValue::HeaderValue
(
HeaderValue
&&other ) noexcept
17
: _val (
new
std::variant<std::monostate, std::string, int32_t, int64_t, double, bool>( std::move(*other._val) ) )
18
{}
19
20
HeaderValue::HeaderValue
(
const
bool
val )
21
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>(val) )
22
{}
23
24
HeaderValue::HeaderValue
(
const
int32_t val )
25
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>(val) )
26
{}
27
28
HeaderValue::HeaderValue
(
const
int64_t val )
29
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>(val) )
30
{}
31
32
HeaderValue::HeaderValue
(
const
double
val )
33
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>(val) )
34
{}
35
36
HeaderValue::HeaderValue
(
const
std::string &val )
37
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>(val) )
38
{}
39
40
HeaderValue::HeaderValue
(
const
char
*val)
41
:
HeaderValue
(
zypp
::
str
::asString (val) )
42
{}
43
44
HeaderValue::HeaderValue
( std::string &&val )
45
: _val ( new
std
::variant<
std
::monostate,
std
::string, int32_t, int64_t, double,
bool
>(
std
::move(val) ) )
46
{}
47
48
bool
HeaderValue::valid
()
const
49
{
50
return
(
_val
->index () > 0 );
51
}
52
53
bool
HeaderValue::isString
()
const
54
{
55
return
std::holds_alternative<std::string>(*
_val
);
56
}
57
58
bool
HeaderValue::isInt
()
const
59
{
60
return
std::holds_alternative<int32_t>(*
_val
);
61
}
62
63
bool
HeaderValue::isInt64
()
const
64
{
65
return
std::holds_alternative<int64_t>(*
_val
);
66
}
67
68
bool
HeaderValue::isDouble
()
const
69
{
70
return
std::holds_alternative<double>(*
_val
);
71
}
72
73
bool
HeaderValue::isBool
()
const
74
{
75
return
std::holds_alternative<bool>(*
_val
);
76
}
77
78
const
std::string &
HeaderValue::asString
()
const
79
{
80
return
std::get<std::string>(*
_val
);
81
}
82
83
int32_t
HeaderValue::asInt
()
const
84
{
85
return
std::get<int32_t>(*
_val
);
86
}
87
88
int64_t
HeaderValue::asInt64
()
const
89
{
90
if
( std::holds_alternative<int32_t>(*
_val
) )
91
return
std::get<int32_t>( *
_val
);
92
return
std::get<int64_t>(*
_val
);
93
}
94
95
double
HeaderValue::asDouble
()
const
96
{
97
return
std::get<double>(*
_val
);
98
}
99
100
bool
HeaderValue::asBool
()
const
101
{
102
return
std::get<bool>(*
_val
);
103
}
104
105
HeaderValue::value_type
&
HeaderValue::asVariant
()
106
{
107
return
*
_val
;
108
}
109
110
const
HeaderValue::value_type
&
HeaderValue::asVariant
()
const
111
{
112
return
*
_val
;
113
}
114
115
HeaderValue
&
HeaderValue::operator=
(
const
HeaderValue
&other)
116
{
117
*
_val
= *other.
_val
;
118
return
*
this
;
119
}
120
121
bool
HeaderValue::operator==
(
const
HeaderValue
&other)
const
122
{
123
return
( *
_val
== *other.
_val
);
124
}
125
126
HeaderValue
&
HeaderValue::operator=
(
HeaderValue
&&other )
noexcept
127
{
128
*_val = std::move( *other._val );
129
return
*
this
;
130
}
131
132
HeaderValue
&
HeaderValue::operator=
(
const
std::string &val )
133
{
134
*
_val
= val;
135
return
*
this
;
136
}
137
138
HeaderValue
&
HeaderValue::operator=
( int32_t val )
139
{
140
*
_val
= val;
141
return
*
this
;
142
}
143
144
HeaderValue
&
HeaderValue::operator=
( int64_t val )
145
{
146
*
_val
= val;
147
return
*
this
;
148
}
149
150
HeaderValue
&
HeaderValue::operator=
(
double
val )
151
{
152
*
_val
= val;
153
return
*
this
;
154
}
155
156
HeaderValue
&
HeaderValue::operator=
(
bool
val )
157
{
158
*
_val
= val;
159
return
*
this
;
160
}
161
162
163
HeaderValueMap::HeaderValueMap
( std::initializer_list<HeaderValueMap::ValueMap::value_type> init )
164
: _values(
std
::move(init) )
165
{ }
166
167
bool
HeaderValueMap::contains
(
const
std::string &key)
const
168
{
169
return
_values
.count (key) > 0 &&
_values
.at(key).size () > 0 ;
170
}
171
172
void
HeaderValueMap::set
(
const
std::string &key,
const
Value
&val )
173
{
174
auto
i =
_values
.find (key);
175
if
( i ==
_values
.end() ) {
176
_values
.insert ( std::make_pair(key, std::vector<Value>{val}) );
177
}
else
{
178
i->second = std::vector<Value>{val};
179
}
180
}
181
182
void
HeaderValueMap::set
(
const
std::string &key,
Value
&&val)
183
{
184
auto
i =
_values
.find (key);
185
if
( i ==
_values
.end() ) {
186
_values
.insert ( std::make_pair(key, std::vector<Value>{std::move(val)}) );
187
}
else
{
188
i->second = std::vector<Value>{std::move(val)};
189
}
190
}
191
192
void
HeaderValueMap::add
(
const
std::string &key,
const
Value
&val)
193
{
194
auto
i =
_values
.find (key);
195
if
( i ==
_values
.end() ) {
196
_values
.insert ( std::make_pair(key, std::vector<Value>{val}) );
197
}
else
{
198
i->second.push_back(val);
199
}
200
}
201
202
void
HeaderValueMap::clear
()
203
{
204
_values
.clear();
205
}
206
207
HeaderValueMap::ValueMap::size_type
HeaderValueMap::size
() const noexcept
208
{
209
return
_values
.size();
210
}
211
212
std::vector<HeaderValueMap::Value> &
HeaderValueMap::values
(
const
std::string &key)
213
{
214
return
_values
[key];
215
}
216
217
const
std::vector<HeaderValueMap::Value> &
HeaderValueMap::values
(
const
std::string &key)
const
218
{
219
return
_values
.at(key);
220
}
221
222
HeaderValueMap::Value
HeaderValueMap::value
(
const
std::string_view &
str
,
const
HeaderValueMap::Value
&defaultVal)
const
223
{
return
value
( std::string(
str
), defaultVal ); }
224
225
HeaderValueMap::Value
HeaderValueMap::value
(
const
std::string &
str
,
const
HeaderValueMap::Value
&defaultVal)
const
226
{
227
if
( !
contains
(
str
) || !
_values
.at(
str
).size() )
228
return
defaultVal;
229
return
_values
.at(
str
).back();
230
}
231
232
HeaderValueMap::Value
&
HeaderValueMap::operator[]
(
const
std::string &key)
233
{
234
if
( !
contains
(key) )
235
return
InvalidValue
;
236
return
_values
[key].back();
237
}
238
239
HeaderValueMap::Value
&
HeaderValueMap::operator[]
(
const
std::string_view &key )
240
{
241
return
(*
this
)[std::string(key)];
242
}
243
244
const
HeaderValueMap::Value
&
HeaderValueMap::operator[]
(
const
std::string &key )
const
245
{
246
if
( !
contains
(key) )
247
return
InvalidValue
;
248
return
_values
.at(key).back();
249
}
250
251
const
HeaderValueMap::Value
&
HeaderValueMap::operator[]
(
const
std::string_view &key )
const
252
{
253
return
(*
this
)[std::string(key)];
254
}
255
256
HeaderValueMap::const_iterator
HeaderValueMap::erase
(
const
const_iterator
&i)
257
{
258
auto
yi =
_values
.erase(i.base());
259
return
HeaderValueMap::const_iterator
(yi);
260
}
261
262
bool
HeaderValueMap::erase
(
const
std::string &key)
263
{
264
return
(
_values
.erase(key) > 0 );
265
}
266
267
}
bool
zyppng::HeaderValueMap::const_iterator
Definition
headervaluemap.h:84
zyppng::HeaderValueMap::InvalidValue
static Value InvalidValue
Definition
headervaluemap.h:75
zyppng::HeaderValueMap::add
void add(const std::string &key, const Value &val)
Definition
headervaluemap.cc:192
zyppng::HeaderValueMap::operator[]
Value & operator[](const std::string &key)
Definition
headervaluemap.cc:232
zyppng::HeaderValueMap::erase
const_iterator erase(const const_iterator &i)
Definition
headervaluemap.cc:256
zyppng::HeaderValueMap::Value
HeaderValue Value
Definition
headervaluemap.h:72
zyppng::HeaderValueMap::clear
void clear()
Definition
headervaluemap.cc:202
zyppng::HeaderValueMap::_values
ValueMap _values
Definition
headervaluemap.h:188
zyppng::HeaderValueMap::value
Value value(const std::string_view &str, const Value &defaultVal=Value()) const
Definition
headervaluemap.cc:222
zyppng::HeaderValueMap::contains
bool contains(const std::string &key) const
Definition
headervaluemap.cc:167
zyppng::HeaderValueMap::HeaderValueMap
HeaderValueMap()=default
zyppng::HeaderValueMap::size
ValueMap::size_type size() const noexcept
Definition
headervaluemap.cc:207
zyppng::HeaderValueMap::values
std::vector< Value > & values(const std::string &key)
Definition
headervaluemap.cc:212
zyppng::HeaderValueMap::set
void set(const std::string &key, const Value &val)
Definition
headervaluemap.cc:172
zyppng::HeaderValue
Definition
headervaluemap.h:21
zyppng::HeaderValue::asVariant
value_type & asVariant()
Definition
headervaluemap.cc:105
zyppng::HeaderValue::operator==
bool operator==(const HeaderValue &other) const
Definition
headervaluemap.cc:121
zyppng::HeaderValue::HeaderValue
HeaderValue()
Definition
headervaluemap.cc:8
zyppng::HeaderValue::_val
zypp::RWCOW_pointer< value_type > _val
Definition
headervaluemap.h:66
zyppng::HeaderValue::asDouble
double asDouble() const
Definition
headervaluemap.cc:95
zyppng::HeaderValue::operator=
HeaderValue & operator=(const HeaderValue &other)
Definition
headervaluemap.cc:115
zyppng::HeaderValue::asInt
int32_t asInt() const
Definition
headervaluemap.cc:83
zyppng::HeaderValue::isInt
bool isInt() const
Definition
headervaluemap.cc:58
zyppng::HeaderValue::isInt64
bool isInt64() const
Definition
headervaluemap.cc:63
zyppng::HeaderValue::asString
const std::string & asString() const
Definition
headervaluemap.cc:78
zyppng::HeaderValue::value_type
std::variant< std::monostate, std::string, int32_t, int64_t, double, bool > value_type
Definition
headervaluemap.h:23
zyppng::HeaderValue::isString
bool isString() const
Definition
headervaluemap.cc:53
zyppng::HeaderValue::asBool
bool asBool() const
Definition
headervaluemap.cc:100
zyppng::HeaderValue::isDouble
bool isDouble() const
Definition
headervaluemap.cc:68
zyppng::HeaderValue::valid
bool valid() const
Definition
headervaluemap.cc:48
zyppng::HeaderValue::isBool
bool isBool() const
Definition
headervaluemap.cc:73
zyppng::HeaderValue::asInt64
int64_t asInt64() const
Definition
headervaluemap.cc:88
headervaluemap.h
std
Definition
Arch.h:364
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition
CodePitfalls.doc:2
zyppng
Definition
MediaNetwork.h:23
zypp-media
ng
headervaluemap.cc
Generated by
1.10.0