userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
generic_optional.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/ydb/io/generic_optional.hpp
4
/// @brief YDB std::optional value traits implementation
5
6
#
include
<
ydb
-
cpp
-
sdk
/
client
/
value
/
value
.
h
>
7
8
#
include
<
optional
>
9
10
#
include
<
userver
/
ydb
/
io
/
traits
.
hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
ydb::impl {
15
16
template
<
typename
T>
17
struct
GenericOptionalValueTraits {
18
static
std::optional<T> Parse(NYdb::TValueParser& parser,
const
ParseContext& context) {
19
std::optional<T> result;
20
parser.OpenOptional();
21
if
(!parser.IsNull()) {
22
result.emplace(
ValueTraits
<T>::Parse(parser, context));
23
}
24
parser.CloseOptional();
25
return
result;
26
}
27
28
template
<
typename
Builder,
typename
U =
const
std::optional<T>&>
29
static
void
Write(NYdb::TValueBuilderBase<Builder>& builder, U&& value) {
30
if
(value.has_value()) {
31
builder.BeginOptional();
32
ValueTraits
<T>::Write(builder, std::forward<U>(value).value());
33
builder.EndOptional();
34
}
else
{
35
builder.EmptyOptional(
ValueTraits
<T>::MakeType());
36
}
37
}
38
39
static
NYdb::TType MakeType() {
40
NYdb::TTypeBuilder builder;
41
builder.Optional(
ValueTraits
<T>::MakeType());
42
return
builder.Build();
43
}
44
};
45
46
}
// namespace ydb::impl
47
48
USERVER_NAMESPACE_END
userver
ydb
io
generic_optional.hpp
Generated on
for userver by
Doxygen
1.17.0