-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisitor.h
49 lines (38 loc) · 1.48 KB
/
visitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <string>
namespace flexi_cfg::visitor {
template <typename Visitor>
concept KeyVisitor = requires(Visitor& visitor, std::string key) { visitor.onKey(key); };
template <typename Visitor>
concept BoolValueVisitor = KeyVisitor<Visitor> && requires(Visitor& visitor, bool value) {
{ visitor.onValue(value) };
};
template <typename Visitor>
concept IntValueVisitor =
KeyVisitor<Visitor> && requires(Visitor& visitor, int64_t value, uint64_t unsigned_value) {
{ visitor.onValue(value) };
{ visitor.onValue(unsigned_value) };
};
template <typename Visitor>
concept FloatValueVisitor = KeyVisitor<Visitor> && requires(Visitor& visitor, double value) {
{ visitor.onValue(value) };
};
template <typename Visitor>
concept StringValueVisitor = KeyVisitor<Visitor> && requires(Visitor& visitor, std::string value) {
{ visitor.onValue(value) };
};
template <typename Visitor>
concept ListVisitor = requires(Visitor& visitor) {
{ visitor.beginList() };
{ visitor.endList() };
};
template <typename Visitor>
concept StructVisitor = KeyVisitor<Visitor> && requires(Visitor& visitor) {
{ visitor.beginStruct() };
{ visitor.endStruct() };
};
template <typename Visitor>
concept TypedVisitor = KeyVisitor<Visitor> || IntValueVisitor<Visitor> ||
FloatValueVisitor<Visitor> || StringValueVisitor<Visitor> ||
BoolValueVisitor<Visitor> || ListVisitor<Visitor> || StructVisitor<Visitor>;
} // namespace flexi_cfg::visitor