userver
C++ Async Framework
Loading...
Searching...
No Matches
validations.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file universal/include/userver/formats/common/validations.hpp
4
/// @brief @copybrief formats::common::ValidateFloat()
5
6
#
include
<
cmath
>
7
8
#
include
<
userver
/
utils
/
assert
.
hpp
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
formats::
common
{
13
14
/// @brief Common restrictions to floating type values serialization. Asserts
15
/// or throws on NaN and Inf values.
16
template
<
typename
ExceptionType,
typename
Float>
17
Float
ValidateFloat
(Float value) {
18
if
(std::isnan(value)) {
19
UASSERT_MSG
(
false
,
"Floating point nan value serialization is forbidden"
);
20
throw
ExceptionType(
"Floating point nan value serialization is forbidden"
);
21
}
22
if
(std::isinf(value)) {
23
UASSERT_MSG
(
false
,
"Floating point inf value serialization is forbidden"
);
24
throw
ExceptionType(
"Floating point inf value serialization is forbidden"
);
25
}
26
return
value;
27
}
28
29
}
// namespace formats::common
30
31
USERVER_NAMESPACE_END
userver
formats
common
validations.hpp
Generated on Tue Nov 19 2024 11:33:17 for userver by
Doxygen
1.10.0