userver: userver/formats/json/parser/validator.hpp Source File
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
9USERVER_NAMESPACE_BEGIN
10
11namespace formats::json::parser {
12
13template <typename T>
15public:
16 virtual void operator()(const T& t) const = 0;
17};
18
19template <typename T, typename F>
20class Validator final : public BaseValidator<T> {
21public:
22 explicit Validator(F f)
23 : f_(std::move(f))
24 {}
25
26 void operator()(const T& t) const override { f_(t); }
27
28private:
29 F f_;
30};
31
32template <typename T>
33class EmptyValidator final : public BaseValidator<T> {
34public:
35 void operator()(const T&) const override {}
36};
37
38template <typename T, typename F>
39auto MakeValidator(F f) {
40 return Validator<T, F>(std::move(f));
41}
42
43template <typename T>
44inline constexpr EmptyValidator<T> kEmptyValidator;
45
46} // namespace formats::json::parser
47
48USERVER_NAMESPACE_END