userver
C++ Async Framework
Loading...
Searching...
No Matches
boost_uuid.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/formats/parse/boost_uuid.hpp
4
/// @brief boost::uuids::uuid parser for any format
5
/// @ingroup userver_universal userver_formats_parse
6
7
#
include
<
optional
>
8
#
include
<
string
>
9
10
#
include
<
boost
/
uuid
/
uuid
.
hpp
>
11
12
#
include
<
userver
/
formats
/
common
/
meta
.
hpp
>
13
#
include
<
userver
/
formats
/
parse
/
to
.
hpp
>
14
#
include
<
userver
/
utils
/
boost_uuid4
.
hpp
>
15
16
USERVER_NAMESPACE_BEGIN
17
18
namespace
formats::
parse
{
19
20
/**
21
* Valid uuid strings:
22
* 0123456789abcdef0123456789abcdef
23
* 01234567-89ab-cdef-0123-456789abcdef
24
* {01234567-89ab-cdef-0123-456789abcdef}
25
* {0123456789abcdef0123456789abcdef}
26
*/
27
template
<
typename
Value>
28
std
::
enable_if_t
<
common
::
kIsFormatValue
<
Value
>,
boost
::
uuids
::
uuid
>
Parse
(
29
const
Value
&
value
,
To
<
boost
::
uuids
::
uuid
>) {
30
std::optional<std::string> str;
31
try
{
32
str = value.
template
As<std::string>();
33
return
utils::BoostUuidFromString(*str);
34
}
catch
(
const
std::exception& e) {
35
if
(!!str) {
36
throw
typename
Value::ParseException(
37
"'"
+ *str +
"' cannot be parsed to `boost::uuids::uuid`"
);
38
}
else
{
39
throw
typename
Value::ParseException(
40
"Only strings can be parsed as boost uuid"
);
41
}
42
}
43
}
44
45
}
// namespace formats::parse
46
47
USERVER_NAMESPACE_END
userver
formats
parse
boost_uuid.hpp
Generated on Thu Oct 3 2024 13:15:41 for userver by
Doxygen
1.10.0