Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RawAbstraction.hpp
Go to the documentation of this file.
1
6#pragma once
7
10
11namespace abstraction {
12
13class RawAbstraction : virtual public OperationAbstraction {
15 std::function < std::shared_ptr < abstraction::Value > ( const std::vector < std::shared_ptr < abstraction::Value > > & ) > m_callback;
16 std::vector < std::shared_ptr < abstraction::Value > > m_params;
17
18public:
19 explicit RawAbstraction ( ext::vector < ext::pair < std::string, abstraction::TypeQualifiers::TypeQualifierSet > > paramSpecs, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > callback ) : m_paramSpecs ( std::move ( paramSpecs ) ), m_callback ( std::move ( callback ) ), m_params ( m_paramSpecs.size ( ) ) {
20 }
21
22private:
23 std::shared_ptr < abstraction::Value > run ( ) const {
24 return m_callback ( m_params );
25 }
26
27 void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override;
28
29 void detachInput ( size_t index ) override;
30
31public:
32 bool inputsAttached ( ) const override;
33
34 std::shared_ptr < abstraction::Value > eval ( ) override;
35
36 size_t numberOfParams ( ) const override {
37 return m_params.size ( );
38 }
39
40 bool isParamTypeUniversal ( size_t ) const override {
41 return true;
42 }
43
44 ext::type_index getParamTypeIndex ( size_t index ) const override {
45 if ( index >= m_params.size ( ) )
46 throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
47
48 if ( m_params [ index ] == nullptr )
49 throw std::domain_error ( "Parameter index " + ext::to_string ( index ) + " not yet set.");
50
51 return m_params [ index ]->getTypeIndex ( );
52 }
53
55 if ( index >= m_params.size ( ) )
56 throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
57
58 if ( m_params [ index ] == nullptr )
59 throw std::domain_error ( "Parameter index " + ext::to_string ( index ) + " not yet set.");
60
61 return m_params [ index ]->getTypeQualifiers ( );
62 }
63
64 bool isReturnTypeUniversal ( ) const override {
65 return true;
66 }
67
69 throw std::domain_error ( "Return type not available.");
70 }
71
73 throw std::domain_error ( "Return type not available.");
74 }
75
76};
77
78} /* namespace abstraction */
79
Definition: OperationAbstraction.hpp:19
Definition: RawAbstraction.hpp:13
ext::type_index getParamTypeIndex(size_t index) const override
Definition: RawAbstraction.hpp:44
abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers() const override
Definition: RawAbstraction.hpp:68
size_t numberOfParams() const override
Definition: RawAbstraction.hpp:36
bool isParamTypeUniversal(size_t) const override
Definition: RawAbstraction.hpp:40
RawAbstraction(ext::vector< ext::pair< std::string, abstraction::TypeQualifiers::TypeQualifierSet > > paramSpecs, std::function< std::shared_ptr< abstraction::Value >(std::vector< std::shared_ptr< abstraction::Value > >) > callback)
Definition: RawAbstraction.hpp:19
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers(size_t index) const override
Definition: RawAbstraction.hpp:54
std::shared_ptr< abstraction::Value > eval() override
Definition: RawAbstraction.cpp:32
bool isReturnTypeUniversal() const override
Definition: RawAbstraction.hpp:64
bool inputsAttached() const override
Definition: RawAbstraction.cpp:24
ext::type_index getReturnTypeIndex() const override
Definition: RawAbstraction.hpp:72
TypeQualifierSet
Definition: TypeQualifiers.hpp:15
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: typeindex.h:37
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Definition: AlgorithmAbstraction.hpp:11
int callback(struct dl_phdr_info *info, size_t, void *data)
Definition: simpleStacktrace.cpp:25
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
Definition: FordFulkerson.hpp:16