userver
C++ Async Framework
Loading...
Searching...
No Matches
validator.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/formats/json/parser/validator.hpp
4
/// @brief Lightweight validators for parsed JSON values.
5
/// @ingroup userver_universal
6
7
#
include
<
utility
>
8
9
USERVER_NAMESPACE_BEGIN
10
11
namespace
formats::json::
parser
{
12
13
template
<
typename
T>
14
class
BaseValidator
{
15
public
:
16
virtual
void
operator()(
const
T& t)
const
= 0;
17
};
18
19
template
<
typename
T,
typename
F>
20
class
Validator
final
:
public
BaseValidator
<T> {
21
public
:
22
explicit
Validator(F f)
23
: f_(std::move(f))
24
{}
25
26
void
operator()(
const
T& t)
const
override
{ f_(t); }
27
28
private
:
29
F f_;
30
};
31
32
template
<
typename
T>
33
class
EmptyValidator
final
:
public
BaseValidator
<T> {
34
public
:
35
void
operator()(
const
T&)
const
override
{}
36
};
37
38
template
<
typename
T,
typename
F>
39
auto
MakeValidator(F f) {
40
return
Validator<T, F>(std::move(f));
41
}
42
43
template
<
typename
T>
44
inline
constexpr
EmptyValidator<T> kEmptyValidator;
45
46
}
// namespace formats::json::parser
47
48
USERVER_NAMESPACE_END
userver
formats
json
parser
validator.hpp
Generated on Thu May 21 2026 16:22:25 for userver by
Doxygen
1.13.2