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 } // namespace details
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) { return accept(_node, _args...); }
50#define KDB_SPARQL_ALGEBRA_GENERATE(_KLASS_NAME_, _MEMBER_DEF_) \
51private: \
52 virtual _TR_ visit(_KLASS_NAME_##CSP _node, const _TArgs_&... _parameter) = 0; \
53 virtual void call_visit(_KLASS_NAME_##CSP _node, void* _r, void* _parameter) override \
54 { \
55 typedef _TR_ (AbstractNodeVisitor::*F)(_KLASS_NAME_##CSP _node, const _TArgs_&...); \
56 *reinterpret_cast<_TR_*>(_r) \
57 = std::apply(F(&AbstractNodeVisitor::visit), \
58 std::tuple_cat(std::make_tuple(this, _node), \
59 *reinterpret_cast<ParametersTuple*>(_parameter))); \
60 }
61#include "NodesDefs.h"
62#undef KDB_SPARQL_ALGEBRA_GENERATE
63 protected:
64 _TR_ accept(NodeCSP _node, const _TArgs_... _arguments)
65 {
66 return accept(_node.data(), _arguments...);
67 }
68 _TR_ accept(const Node* _node, const _TArgs_... _arguments)
69 {
70 _TR_ r;
71 if(_node)
72 {
73 ParametersTuple pt = std::make_tuple(_arguments...);
74 _node->accept(this, &r, &pt);
75 }
76 return r;
77 }
78 };
79
80 template<typename... _TArgs_>
82 {
83 friend class Node;
84 public:
85 using ParametersTuple = std::tuple<_TArgs_...>;
86 static constexpr std::size_t ParametersCount = sizeof...(_TArgs_);
87 using ReturnType = void;
88 public:
91 public:
95 void start(NodeCSP _node, const _TArgs_&... _args) { accept(_node, _args...); }
96#define KDB_SPARQL_ALGEBRA_GENERATE(_KLASS_NAME_, _MEMBER_DEF_) \
97private: \
98 virtual void visit(_KLASS_NAME_##CSP _node, const _TArgs_&... _parameter) = 0; \
99 virtual void call_visit(_KLASS_NAME_##CSP _node, void*, void* _parameter) override \
100 { \
101 typedef void (AbstractNodeVisitor::*F)(_KLASS_NAME_##CSP _node, const _TArgs_&...); \
102 std::apply(F(&AbstractNodeVisitor::visit), \
103 std::tuple_cat(std::make_tuple(this, _node), \
104 *reinterpret_cast<ParametersTuple*>(_parameter))); \
105 }
106#include "NodesDefs.h"
107#undef KDB_SPARQL_ALGEBRA_GENERATE
108 protected:
109 void accept(NodeCSP _node, const _TArgs_&... _arguments)
110 {
111 accept(_node.data(), _arguments...);
112 }
113 void accept(const Node* _node, const _TArgs_&... _arguments)
114 {
115 if(_node)
116 {
117 ParametersTuple pt = std::make_tuple(_arguments...);
118 _node->accept(this, nullptr, &pt);
119 }
120 }
121 };
122} // namespace kDB::SPARQL::Algebra
123
124#endif
void start(NodeCSP _node, const _TArgs_ &... _args)
Definition AbstractNodeVisitor.h:95
_TR_ start(NodeCSP _node, const _TArgs_ &... _args)
Definition AbstractNodeVisitor.h:49
Definition Node.h:21