8#include <ext/functional>
15#include <ext/typeinfo>
67 template <
class Return,
class FirstParam,
class SecondParam >
68 class BinaryOperator :
public BinaryEntry {
69 std::function < Return ( FirstParam, SecondParam ) > m_callback;
72 explicit BinaryOperator ( std::function < Return ( FirstParam, SecondParam ) >
callback ) : BinaryEntry (
AlgorithmFullInfo::operatorEntryInfo < Return, FirstParam, SecondParam > ( ) ), m_callback (
std::move (
callback ) ) {
75 std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( )
const override;
78 template <
class Return,
class Param >
79 class PrefixOperator :
public PrefixEntry {
80 std::function < Return ( Param ) > m_callback;
83 explicit PrefixOperator ( std::function < Return ( Param ) >
callback ) :
PrefixEntry ( AlgorithmFullInfo::operatorEntryInfo < Return, Param > ( ) ), m_callback (
std::move (
callback ) ) {
86 std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( )
const override;
89 template <
class Return,
class Param >
90 class PostfixOperator :
public PostfixEntry {
91 std::function < Return ( Param ) > m_callback;
94 explicit PostfixOperator ( std::function < Return ( Param ) >
callback ) :
PostfixEntry ( AlgorithmFullInfo::operatorEntryInfo < Return, Param > ( ) ), m_callback (
std::move (
callback ) ) {
97 std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( )
const override;
129 template <
class FirstParam,
class SecondParam >
131 unregisterBinaryInternal ( type, AlgorithmBaseInfo::operatorEntryInfo < FirstParam, SecondParam > ( ) );
134 template <
class Return,
class FirstParam,
class SecondParam >
136 registerBinaryInternal ( type, std::make_unique < BinaryOperator < Return, FirstParam, SecondParam > > ( func ) );
139 template < Operators::BinaryOperators Type,
class FirstParam,
class SecondParam >
142 std::function < decltype ( std::declval < FirstParam > ( ) && std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a && b; };
145 std::function < decltype ( std::declval < FirstParam > ( ) || std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a || b; };
148 std::function < decltype ( std::declval < FirstParam > ( ) & std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a & b; };
151 std::function < decltype ( std::declval < FirstParam > ( ) | std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a | b; };
154 std::function < decltype ( std::declval < FirstParam > ( ) ^ std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a ^ b; };
157 std::function < decltype ( std::declval < FirstParam > ( ) + std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a + b; };
160 std::function < decltype ( std::declval < FirstParam > ( ) - std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a - b; };
163 std::function < decltype ( std::declval < FirstParam > ( ) * std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a * b; };
166 std::function < decltype ( std::declval < FirstParam > ( ) % std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a % b; };
169 std::function < decltype ( std::declval < FirstParam > ( ) / std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a / b; };
172 std::function < decltype ( std::declval < FirstParam > ( ) == std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a == b; };
175 std::function < decltype ( std::declval < FirstParam > ( ) != std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a != b; };
178 std::function < decltype ( std::declval < FirstParam > ( ) < std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a < b; };
181 std::function < decltype ( std::declval < FirstParam > ( ) <= std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a <= b; };
184 std::function < decltype ( std::declval < FirstParam > ( ) > std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a > b; };
187 std::function < decltype ( std::declval < FirstParam > ( ) >= std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) {
return a >= b; };
190 std::function < decltype ( std::declval < FirstParam > ( ) = std::declval < SecondParam > ( ) ) ( FirstParam, SecondParam ) >
callback = [ ] ( FirstParam a, SecondParam b ) ->
decltype (
auto ) {
return a = b; };
193 static_assert (
"Unhandled binary operator." );
202 template <
class Param >
204 unregisterPrefixInternal ( type, AlgorithmBaseInfo::operatorEntryInfo < Param > ( ) );
207 template <
class Return,
class Param >
209 registerPrefixInternal ( type, std::make_unique < PrefixOperator < Return, Param > > ( func ) );
212 template < Operators::PrefixOperators Type,
class Param >
215 std::function < decltype ( + std::declval < Param > ( ) ) ( Param ) >
callback = [ ] ( Param a ) {
return + a; };
218 std::function <
decltype ( - std::declval < Param > ( ) ) ( Param ) >
callback = [ ] ( Param a ) ->
decltype (
auto ) {
return - a; };
221 std::function < decltype ( ! std::declval < Param > ( ) ) ( Param ) >
callback = [ ] ( Param a ) ->
decltype (
auto ) {
return ! a; };
224 std::function < decltype ( ~ std::declval < Param > ( ) ) ( Param ) >
callback = [ ] ( Param a ) ->
decltype (
auto ) {
return ~ a; };
227 std::function < decltype ( ++ std::declval < Param > ( ) ) ( Param ) >
callback = [ ] ( Param a ) ->
decltype (
auto ) {
return ++ a; };
230 std::function <
decltype ( -- std::declval < Param > ( ) ) ( Param ) >
callback = [ ] ( Param a ) ->
decltype (
auto ) {
return -- a; };
233 static_assert (
"Unhandled prefix operator." );
242 template <
class Param >
244 unregisterPostfixInternal ( type, AlgorithmBaseInfo::operatorEntryInfo < Param > ( ) );
247 template <
class Return,
class Param >
249 registerPostfixInternal ( type, std::make_unique < PostfixOperator < Return, Param > > ( func ) );
252 template < Operators::PostfixOperators Type,
class Param >
255 std::function < decltype ( std::declval < Param > ( ) ++ ) ( Param ) >
callback = [ ] ( Param a ) { std::decay_t < Param > tmp = a; a ++;
return tmp; };
258 std::function < decltype ( std::declval < Param > ( ) -- ) ( Param ) >
callback = [ ] ( Param a ) { std::decay_t < Param > tmp = a; a --;
return tmp; };
261 static_assert (
"Unhandled postfix operator." );
279template <
class Return,
class FirstParam,
class SecondParam >
280std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::BinaryOperator < Return, FirstParam, SecondParam >::getAbstraction ( )
const {
281 return std::make_shared < abstraction::AlgorithmAbstraction < Return, FirstParam, SecondParam > > ( m_callback );
284template <
class Return,
class Param >
285std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::PrefixOperator < Return, Param >::getAbstraction ( )
const {
286 return std::make_shared < abstraction::AlgorithmAbstraction < Return, Param > > ( m_callback );
289template <
class Return,
class Param >
290std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::PostfixOperator < Return, Param >::getAbstraction ( )
const {
291 return std::make_shared < abstraction::AlgorithmAbstraction < Return, Param > > ( m_callback );
AlgorithmCategory
Definition: AlgorithmCategories.hpp:14
Definition: AlgorithmRegistryInfo.hpp:89
Definition: BaseRegistryEntry.hpp:12
Definition: OperatorRegistry.hpp:30
const AlgorithmFullInfo & getEntryInfo() const
Definition: OperatorRegistry.hpp:37
BinaryEntry(AlgorithmFullInfo entryInfo)
Definition: OperatorRegistry.hpp:34
Definition: OperatorRegistry.hpp:54
PostfixEntry(AlgorithmFullInfo entryInfo)
Definition: OperatorRegistry.hpp:58
const AlgorithmFullInfo & getEntryInfo() const
Definition: OperatorRegistry.hpp:61
Definition: OperatorRegistry.hpp:42
PrefixEntry(AlgorithmFullInfo entryInfo)
Definition: OperatorRegistry.hpp:46
const AlgorithmFullInfo & getEntryInfo() const
Definition: OperatorRegistry.hpp:49
Definition: OperatorRegistry.hpp:28
static std::shared_ptr< abstraction::OperationAbstraction > getPostfixAbstraction(Operators::PostfixOperators type, const ext::vector< std::string > ¶mTypes, const ext::vector< abstraction::TypeQualifiers::TypeQualifierSet > &typeQualifiers, AlgorithmCategories::AlgorithmCategory category)
Definition: OperatorRegistry.cpp:154
static void registerBinary()
Definition: OperatorRegistry.hpp:140
static ext::list< ext::pair< Operators::PrefixOperators, AlgorithmFullInfo > > listPrefixOverloads()
Definition: OperatorRegistry.cpp:109
static void registerPostfix()
Definition: OperatorRegistry.hpp:253
static ext::list< ext::pair< Operators::BinaryOperators, AlgorithmFullInfo > > listBinaryOverloads()
Definition: OperatorRegistry.cpp:58
static void unregisterPostfix(Operators::PostfixOperators type)
Definition: OperatorRegistry.hpp:243
static void registerPrefix(Operators::PrefixOperators type, std::function< Return(Param) > func)
Definition: OperatorRegistry.hpp:208
static std::shared_ptr< abstraction::OperationAbstraction > getBinaryAbstraction(Operators::BinaryOperators type, const ext::vector< std::string > ¶mTypes, const ext::vector< abstraction::TypeQualifiers::TypeQualifierSet > &typeQualifiers, AlgorithmCategories::AlgorithmCategory category)
Definition: OperatorRegistry.cpp:52
static void registerPostfix(Operators::PostfixOperators type, std::function< Return(Param) > func)
Definition: OperatorRegistry.hpp:248
static void unregisterPrefix(Operators::PrefixOperators type)
Definition: OperatorRegistry.hpp:203
static void registerPrefix()
Definition: OperatorRegistry.hpp:213
static void unregisterBinary(Operators::BinaryOperators type)
Definition: OperatorRegistry.hpp:130
static void registerBinary(Operators::BinaryOperators type, std::function< Return(FirstParam, SecondParam) > func)
Definition: OperatorRegistry.hpp:135
static std::shared_ptr< abstraction::OperationAbstraction > getPrefixAbstraction(Operators::PrefixOperators type, const ext::vector< std::string > ¶mTypes, const ext::vector< abstraction::TypeQualifiers::TypeQualifierSet > &typeQualifiers, AlgorithmCategories::AlgorithmCategory category)
Definition: OperatorRegistry.cpp:103
static ext::list< ext::pair< Operators::PostfixOperators, AlgorithmFullInfo > > listPostfixOverloads()
Definition: OperatorRegistry.cpp:160
PostfixOperators
Definition: Operators.hpp:43
PrefixOperators
Definition: Operators.hpp:34
BinaryOperators
Definition: Operators.hpp:14
Class extending the list class from the standard library. Original reason is to allow printing of the...
Definition: list.hpp:44
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
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
Type
Definition: MeasurementTypes.hpp:20
Definition: FordFulkerson.hpp:16