kDB: Knowledge DataBase
Loading...
Searching...
No Matches
AbstractNodeVisitor.h
1#ifndef _KDB_SPARQL_ALGEBRA_ABSTRACT_NODE_VISITOR_H_
2#define _KDB_SPARQL_ALGEBRA_ABSTRACT_NODE_VISITOR_H_
3
4#include "Nodes.h"
5
6namespace kDB::SPARQL::Algebra
7{
8 namespace details
9 {
11 {
12 public:
15 #define KDB_SPARQL_ALGEBRA_GENERATE(_KLASS_NAME_, _MEMBER_DEF_) \
16 virtual void call_visit(_KLASS_NAME_ ## CSP _node, void* _r, void* _parameter) = 0;
17 #include "NodesDefs.h"
18 #undef KDB_SPARQL_ALGEBRA_GENERATE
19 // protected:
20 // void accept(NodeCSP _node, void* _r, void* _parameter)
21 // {
22 // return accept(_r, _node.data(), _parameter);
23 // }
24 // void accept(const Node* _node, void* _r, void* _parameter)
25 // {
26 // if(_node)
27 // {
28 // _node->accept(this, _r, _parameter);
29 // }
30 // }
31 };
32 }
33
34 template<typename _TR_, typename... _TArgs_>
36 {
37 friend class Node;
38 public:
39 using ParametersTuple = std::tuple<_TArgs_...>;
40 static constexpr std::size_t ParametersCount = sizeof...(_TArgs_);
41 using ReturnType = _TR_;
42 public:
44 ~AbstractNodeVisitor() {}
45 public:
49 _TR_ start(NodeCSP _node, const _TArgs_&... _args)
50 {
51 return accept(_node, _args...);
52 }
53#define KDB_SPARQL_ALGEBRA_GENERATE(_KLASS_NAME_, _MEMBER_DEF_) \
54 private: \
55 virtual _TR_ visit(_KLASS_NAME_ ## CSP _node, const _TArgs_&... _parameter) = 0; \
56 virtual void call_visit(_KLASS_NAME_ ## CSP _node, void* _r, void* _parameter) override \
57 { \
58 typedef _TR_ (AbstractNodeVisitor::* F)(_KLASS_NAME_ ## CSP _node, const _TArgs_&...); \
59 *reinterpret_cast<_TR_*>(_r) = std::apply(F(&AbstractNodeVisitor::visit), std::tuple_cat(std::make_tuple(this, _node), \
60 *reinterpret_cast<ParametersTuple*>(_parameter))); \
61 }
62#include "NodesDefs.h"
63#undef KDB_SPARQL_ALGEBRA_GENERATE
64 protected:
65 _TR_ accept(NodeCSP _node, const _TArgs_... _arguments)
66 {
67 return accept(_node.data(), _arguments...);
68 }
69 _TR_ accept(const Node* _node, const _TArgs_... _arguments)
70 {
71 _TR_ r;
72 if(_node)
73 {
74 ParametersTuple pt = std::make_tuple(_arguments...);
75 _node->accept(this, &r, &pt);
76 }
77 return r;
78 }
79 };
80
81 template<typename... _TArgs_>
83 {
84 friend class Node;
85 public:
86 using ParametersTuple = std::tuple<_TArgs_...>;
87 static constexpr std::size_t ParametersCount = sizeof...(_TArgs_);
88 using ReturnType = void;
89 public:
92 public:
96 void start(NodeCSP _node, const _TArgs_&... _args)
97 {
98 accept(_node, _args...);
99 }
100#define KDB_SPARQL_ALGEBRA_GENERATE(_KLASS_NAME_, _MEMBER_DEF_) \
101 private: \
102 virtual void visit(_KLASS_NAME_ ## CSP _node, const _TArgs_&... _parameter) = 0; \
103 virtual void call_visit(_KLASS_NAME_ ## CSP _node, void*, void* _parameter) override \
104 { \
105 typedef void (AbstractNodeVisitor::* F)(_KLASS_NAME_ ## CSP _node, const _TArgs_&...); \
106 std::apply(F(&AbstractNodeVisitor::visit), std::tuple_cat(std::make_tuple(this, _node), *reinterpret_cast<ParametersTuple*>(_parameter) )); \
107 }
108#include "NodesDefs.h"
109#undef KDB_SPARQL_ALGEBRA_GENERATE
110 protected:
111 void accept(NodeCSP _node, const _TArgs_&... _arguments)
112 {
113 accept(_node.data(), _arguments...);
114 }
115 void accept(const Node* _node, const _TArgs_&... _arguments)
116 {
117 if(_node)
118 {
119 ParametersTuple pt = std::make_tuple(_arguments...);
120 _node->accept(this, nullptr, &pt);
121 }
122 }
123 };
124}
125
126#endif
void start(NodeCSP _node, const _TArgs_ &... _args)
Definition AbstractNodeVisitor.h:96
_TR_ start(NodeCSP _node, const _TArgs_ &... _args)
Definition AbstractNodeVisitor.h:49
Definition Node.h:21