-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvisitorList.h
80 lines (63 loc) · 1.75 KB
/
visitorList.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
// Declaration of all visitors
class Debugger;
class VarIndexer;
class ConstProcessor;
template <class T> class Evaluator;
class Compiler;
class ConstCondProcessor;
class IfProcessor;
class DomainProcessor;
template <class T> class FuzzyEvaluator;
// List
// Modifying visitors
#define MVISITORS VarIndexer, ConstProcessor, ConstCondProcessor, IfProcessor, DomainProcessor
// Const visitors
#define CVISITORS Debugger, Evaluator<double>, Compiler, FuzzyEvaluator<double>
// All visitors
#define VISITORS MVISITORS , CVISITORS
// Various meta-programming utilities
// Is V a const visitor?
#include "packIncludes.h"
template <class V>
inline constexpr bool isVisitorConst()
{
return Pack<CVISITORS>::includes<V>();
}
// Use : isVisitorConst<V>() returns true if V is const, or false
// isVisitorConst() resolves at compile time
// Does V have a visit for a const N? A non-const N?
template <typename V>
struct hasNonConstVisit
{
template <typename N, void (V::*) (N&) = &V::visit>
static bool constexpr forNodeType()
{
return true;
}
template <typename N>
static bool constexpr forNodeType(...)
{
return false;
}
};
template <typename V>
struct hasConstVisit
{
template <typename N, void (V::*) (const N&) = &V::visit>
static bool constexpr forNodeType()
{
return true;
}
template <typename N>
static bool constexpr forNodeType(...)
{
return false;
}
};
// Use: hasConstVisit<V>::forNodeType<N>() returns true
// if V declares a method void visit(const N&)
// false otherwise
// Everything resolves at compile time
// hasNonConstVisit is the same: hasNonConstVisit<V>::forNodeType<N>()
// returns true if V declares void visit(N&)