userver: userver/formats/json/parser/validator.hpp Source File
Loading...
Searching...
No Matches
validator.hpp
1#pragma once
2
3#include <utility>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace formats::json::parser {
8
9template <typename T>
10class BaseValidator {
11 public:
12 virtual void operator()(const T& t) const = 0;
13};
14
15template <typename T, typename F>
16class Validator final : public BaseValidator<T> {
17 public:
18 explicit Validator(F f) : f_(std::move(f)) {}
19
20 void operator()(const T& t) const override { f_(t); }
21
22 private:
23 F f_;
24};
25
26template <typename T>
27class EmptyValidator final : public BaseValidator<T> {
28 public:
29 void operator()(const T&) const override {}
30};
31
32template <typename T, typename F>
33auto MakeValidator(F f) {
34 return Validator<T, F>(std::move(f));
35}
36
37template <typename T>
38inline constexpr EmptyValidator<T> kEmptyValidator;
39
40} // namespace formats::json::parser
41
42USERVER_NAMESPACE_END