userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
value_builder.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <chrono>
7
#include <cstddef>
8
#include <cstdint>
9
#include <string>
10
#include <string_view>
11
12
#include <
userver/formats/bson/document.hpp
>
13
#include <
userver/formats/bson/iterator.hpp
>
14
#include <
userver/formats/bson/types.hpp
>
15
#include <
userver/formats/bson/value.hpp
>
16
#include <
userver/formats/common/meta.hpp
>
17
#include <
userver/formats/common/transfer_tag.hpp
>
18
#include <
userver/formats/common/type.hpp
>
19
#include <
userver/utils/strong_typedef.hpp
>
20
21
USERVER_NAMESPACE_BEGIN
22
23
namespace
formats::bson
{
24
39
class
ValueBuilder
{
40
public
:
41
using
iterator =
Iterator<ValueBuilder>
;
42
using
Type =
formats::common::Type
;
43
45
ValueBuilder
();
46
48
ValueBuilder
(
formats::common::Type
type);
49
52
explicit
ValueBuilder
(impl::ValueImplPtr);
54
55
ValueBuilder
(
const
ValueBuilder
& other);
56
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
57
ValueBuilder
(
ValueBuilder
&& other);
58
ValueBuilder
& operator=(
const
ValueBuilder
& other);
59
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
60
ValueBuilder
& operator=(
ValueBuilder
&& other);
61
64
ValueBuilder
(
const
Value
&);
65
ValueBuilder
(
const
Document
&);
66
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
67
ValueBuilder
(
Value
&&);
68
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
69
ValueBuilder
(
Document
&&);
71
74
/* implicit */
ValueBuilder
(std::nullptr_t);
75
/* implicit */
ValueBuilder
(
bool
);
76
/* implicit */
ValueBuilder
(
int
);
77
/* implicit */
ValueBuilder
(
unsigned
int
);
78
/* implicit */
ValueBuilder
(
long
);
79
/* implicit */
ValueBuilder
(
unsigned
long
);
80
/* implicit */
ValueBuilder
(
long
long
);
81
/* implicit */
ValueBuilder
(
unsigned
long
long
);
82
/* implicit */
ValueBuilder
(
double
);
83
/* implicit */
ValueBuilder
(
const
char
*);
84
/* implicit */
ValueBuilder
(
char
*);
85
/* implicit */
ValueBuilder
(std::string);
86
/* implicit */
ValueBuilder
(std::string_view);
87
/* implicit */
ValueBuilder
(
const
std::chrono::system_clock::time_point&);
88
/* implicit */
ValueBuilder
(
const
Oid
&);
89
/* implicit */
ValueBuilder
(
Binary
);
90
/* implicit */
ValueBuilder
(
const
Decimal128
&);
91
/* implicit */
ValueBuilder
(
MinKey
);
92
/* implicit */
ValueBuilder
(
MaxKey
);
93
/* implicit */
ValueBuilder
(
const
Timestamp
&);
95
97
template
<
typename
T>
98
ValueBuilder
(
const
T& t)
99
:
ValueBuilder
(DoSerialize(t))
100
{}
101
104
ValueBuilder
(
common::TransferTag
,
ValueBuilder
&&) noexcept;
105
108
ValueBuilder
operator[](const
std
::
string
& name);
109
113
void
EmplaceNocheck
(
std
::string_view key,
ValueBuilder
value);
114
117
template <typename Tag,
utils
::StrongTypedefOps Ops>
118
requires(
utils
::IsStrongTypedefLoggable(Ops))
119
ValueBuilder
operator[](const
utils
::StrongTypedef<Tag,
std
::
string
, Ops>& name) {
120
return
(*
this
)[name.GetUnderlying()];
121
}
122
126
ValueBuilder
operator[]
(uint32_t index);
127
130
void
Remove
(
const
std::string& key);
131
134
iterator
begin
();
135
138
iterator
end
();
139
143
bool
IsEmpty
()
const
;
144
146
bool
IsNull
() const noexcept;
147
149
bool
IsBool
() const noexcept;
150
152
bool
IsInt
() const noexcept;
153
155
bool
IsInt64
() const noexcept;
156
158
bool
IsUInt64
() const noexcept;
159
161
bool
IsDouble
() const noexcept;
162
164
bool
IsString
() const noexcept;
165
167
bool
IsArray
() const noexcept;
168
170
bool
IsObject
() const noexcept;
171
175
uint32_t
GetSize
() const;
176
180
bool
HasMember
(const
std
::
string
& name) const;
181
183
std
::
string
GetPath
() const;
184
188
void
Resize
(uint32_t size);
189
193
void
PushBack
(
ValueBuilder
&& elem);
194
197
Value
ExtractValue
();
198
199
private:
200
void
Assign(const impl::ValueImplPtr&);
201
void
Assign(impl::ValueImplPtr&&);
202
203
template <typename T>
204
static
Value
DoSerialize(const T& t);
205
206
impl::ValueImplPtr impl_;
207
};
208
209
template <typename T>
210
Value
ValueBuilder
::DoSerialize(const T& t) {
211
static_assert
(
212
formats::common::impl::HasSerialize<Value, T>,
213
"There is no `Serialize(const T&, formats::serialize::To<bson::Value>)` "
214
"in namespace of `T` or `formats::serialize`. "
215
""
216
"Probably you forgot to include the <userver/formats/serialize/common_containers.hpp> or you "
217
"have not provided a `Serialize` function overload."
218
);
219
220
return
Serialize(t,
formats::serialize::To<Value>
());
221
}
222
223
}
// namespace formats::bson
224
225
USERVER_NAMESPACE_END
userver
formats
bson
value_builder.hpp
Generated on
for userver by
Doxygen
1.17.0