Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
visitor.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/utility>
9
10#include <alib/tuple>
11
12namespace core {
13
21template < class ReturnType, class Visitor, class ... Params >
27 typename std::aligned_storage < sizeof ( ReturnType ), alignof ( ReturnType ) >::type result;
28
33 ext::tuple < Params ... > m_params;
34
35public:
40 VisitorContextAux ( Params && ... params ) : m_params ( std::forward < Params > ( params ) ... ) {
41 }
42
47 template < class Inherit, size_t ... Indexes >
48 void call ( const Inherit & inherit, std::index_sequence < Indexes ... > ) {
49 new ( & result ) ReturnType ( Visitor::visit ( inherit, std::forward < Params > ( std::get < Indexes > ( m_params ) ) ... ) );
50 }
51
56 template < class Inherit, size_t ... Indexes >
57 void call ( Inherit & inherit, std::index_sequence < Indexes ... > ) {
58 new ( & result ) ReturnType ( Visitor::visit ( inherit, std::forward < Params > ( std::get < Indexes > ( m_params ) ) ... ) );
59 }
60
65 template < class Inherit, size_t ... Indexes >
66 void call ( Inherit && inherit, std::index_sequence < Indexes ... > ) {
67 new ( & result ) ReturnType ( Visitor::visit ( std::forward < Inherit > ( inherit ), std::forward < Params > ( std::get < Indexes > ( m_params ) ) ... ) );
68 }
69
74 ReturnType getResult ( ) {
75 ReturnType res = reinterpret_cast < ReturnType && > ( result );
76
77 // reinterpret_cast < ReturnType * > ( & result )->~ReturnType ( ); // not needed to delete; data gets moved from on previous line
78 return res;
79 }
80
81};
82
90template < class Visitor, class ... Params >
91class VisitorContextAux < void, Visitor, Params ... > {
92
97 ext::tuple < Params ... > m_params;
98
99public:
104 VisitorContextAux ( Params && ... params ) : m_params ( std::forward < Params > ( params ) ... ) {
105 }
106
111 template < class Inherit, size_t ... Indexes >
112 void call ( const Inherit & inherit, std::index_sequence < Indexes ... > ) {
113 Visitor::visit ( inherit, std::forward < Params > ( std::get < Indexes > ( m_params ) ) ... );
114 }
115
120 template < class Inherit, size_t ... Indexes >
121 void call ( Inherit & inherit, std::index_sequence < Indexes ... > ) {
122 Visitor::visit ( inherit, std::forward < Params > ( std::get < Indexes > ( m_params ) ) ... );
123 }
124
129 template < class Inherit, size_t ... Indexes >
130 void call ( Inherit && inherit, std::index_sequence < Indexes ... > ) {
131 Visitor::visit ( std::forward < Inherit > ( inherit ), std::forward < Params > ( std::get < Indexes > ( m_params ) ) ... );
132 }
133
138 void getResult ( ) {
139 }
140
141};
142
143} /* namespace core */
144
void call(const Inherit &inherit, std::index_sequence< Indexes ... >)
Call method to the visitors visit method. The actuall class of visited object is already evaluated he...
Definition: visitor.hpp:112
void call(Inherit &inherit, std::index_sequence< Indexes ... >)
Call method to the visitors visit method. The actuall class of visited object is already evaluated he...
Definition: visitor.hpp:121
void call(Inherit &&inherit, std::index_sequence< Indexes ... >)
Call method to the visitors visit method. The actuall class of visited object is already evaluated he...
Definition: visitor.hpp:130
VisitorContextAux(Params &&... params)
Constructor for initialisation of the visitor context, i.e. additional call parameters.
Definition: visitor.hpp:104
void getResult()
Visit result getter.
Definition: visitor.hpp:138
Class implementing an actual visitor interface to the visitor.
Definition: visitor.hpp:22
void call(Inherit &&inherit, std::index_sequence< Indexes ... >)
Call method to the visitors visit method. The actuall class of visited object is already evaluated he...
Definition: visitor.hpp:66
void call(Inherit &inherit, std::index_sequence< Indexes ... >)
Call method to the visitors visit method. The actuall class of visited object is already evaluated he...
Definition: visitor.hpp:57
ReturnType getResult()
Visit result getter.
Definition: visitor.hpp:74
VisitorContextAux(Params &&... params)
Constructor for initialisation of the visitor context, i.e. additional call parameters.
Definition: visitor.hpp:40
void call(const Inherit &inherit, std::index_sequence< Indexes ... >)
Call method to the visitors visit method. The actuall class of visited object is already evaluated he...
Definition: visitor.hpp:48
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
return res
Definition: MinimizeByPartitioning.h:145
Definition: normalize.hpp:10
constexpr auto visit(Visitor &&vis, Variants &&... vars)
Definition: variant.hpp:42
Definition: FordFulkerson.hpp:16