Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NaryOperationAbstraction.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/memory>
9#include <ext/array>
10
13
14namespace abstraction {
15
16template < size_t NumberOfParams >
19
20protected:
22 return m_params;
23 }
24
25 virtual std::shared_ptr < abstraction::Value > run ( ) const = 0;
26
27private:
28 void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override {
29 if ( index >= m_params.size ( ) )
30 throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
31
32 m_params [ index ] = input;
33 }
34
35 void detachInput ( size_t index ) override {
36 if ( index >= m_params.size ( ) )
37 throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
38
39 m_params [ index ] = nullptr;
40 }
41
42public:
44 if constexpr ( NumberOfParams != 0 )
45 for ( size_t i = 0; i < NumberOfParams; ++ i ) {
46 m_params [ i ] = nullptr;
47 }
48 }
49
50 bool inputsAttached ( ) const override {
51 return std::all_of ( m_params.begin ( ), m_params.end ( ), [ ] ( const std::shared_ptr < abstraction::Value > & param ) { return static_cast < bool > ( param ); } );
52 }
53
54 std::shared_ptr < abstraction::Value > eval ( ) override {
55 if ( ! inputsAttached ( ) )
56 return nullptr;
57
58 return this->run ( );
59 }
60
61 size_t numberOfParams ( ) const override {
62 return NumberOfParams;
63 }
64
65};
66
67} /* namespace abstraction */
68
73
74namespace abstraction {
75
76template < class ... ParamTypes >
77class NaryOperationAbstraction : virtual public NaryOperationAbstractionImpl < sizeof ... ( ParamTypes ) > {
78public:
79 ext::type_index getParamTypeIndex ( size_t index ) const override {
80 return abstraction::paramType < ParamTypes ... > ( index );
81 }
82
84 return abstraction::paramTypeQualifiers < ParamTypes ... > ( index );
85 }
86
87};
88
89} /* namespace abstraction */
90
Definition: NaryOperationAbstraction.hpp:17
bool inputsAttached() const override
Definition: NaryOperationAbstraction.hpp:50
virtual std::shared_ptr< abstraction::Value > run() const =0
NaryOperationAbstractionImpl()
Definition: NaryOperationAbstraction.hpp:43
size_t numberOfParams() const override
Definition: NaryOperationAbstraction.hpp:61
std::shared_ptr< abstraction::Value > eval() override
Definition: NaryOperationAbstraction.hpp:54
const ext::array< std::shared_ptr< abstraction::Value >, NumberOfParams > & getParams() const
Definition: NaryOperationAbstraction.hpp:21
Definition: NaryOperationAbstraction.hpp:77
ext::type_index getParamTypeIndex(size_t index) const override
Definition: NaryOperationAbstraction.hpp:79
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers(size_t index) const override
Definition: NaryOperationAbstraction.hpp:83
Definition: OperationAbstraction.hpp:19
TypeQualifierSet
Definition: TypeQualifiers.hpp:15
Class extending the array class from the standard library. Original reason is to allow printing of th...
Definition: array.hpp:68
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: array.hpp:123
auto end() &
Inherited behavior of end for non-const instance.
Definition: array.hpp:153
Definition: typeindex.h:37
Definition: AlgorithmAbstraction.hpp:11
abstraction::TypeQualifiers::TypeQualifierSet paramTypeQualifiers(unsigned index)
Definition: AbstractionHelpers.hpp:45
int i
Definition: AllEpsilonClosure.h:118
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
all_of(T &&...) -> all_of< T... >