29 #ifndef AURORA_DOUBLEDISPATCHER_HPP
30 #define AURORA_DOUBLEDISPATCHER_HPP
39 #include <unordered_map>
118 template <
typename Signature,
class Traits = RttiDispatchTraits<Signature, 2>>
126 typedef typename FunctionResult<Signature>::Type
Result;
130 typedef typename FunctionParam<Signature, 0>::Type
Parameter;
134 typedef typename FunctionParam<Signature, 2>::Type
UserData;
141 static_assert(std::is_pointer<Parameter>::value || std::is_lvalue_reference<Parameter>::value,
142 "Function parameter must be a pointer or reference.");
145 static_assert(std::is_same<
typename FunctionParam<Signature, 0>::Type,
typename FunctionParam<Signature, 1>::Type>::value,
146 "The two function parameters must have the same type.");
177 template <
typename Id1,
typename Id2,
typename Fn>
178 void bind(
const Id1& identifier1,
const Id2& identifier2, Fn
function);
190 Result
call(Parameter arg1, Parameter arg2)
const;
204 Result
call(Parameter arg1, Parameter arg2, UserData data)
const;
211 void fallback(std::function<Signature>
function);
217 typedef typename Traits::Key SingleKey;
218 typedef std::function<Signature> BaseFunction;
222 Key(
const SingleKey& key1,
const SingleKey& key2,
bool swapped);
223 bool operator== (
const Key& rhs)
const;
225 std::pair<SingleKey, SingleKey> keyPair;
231 std::size_t operator() (
const Key& k)
const;
234 typedef std::unordered_map<Key, BaseFunction, Hasher> FnMap;
241 Key makeKey(SingleKey key1, SingleKey key2)
const;
248 BaseFunction mFallback;
256 #include <Aurora/Dispatch/Detail/DoubleDispatcher.inl>
257 #endif // AURORA_DOUBLEDISPATCHER_HPP
Utilities for template metaprogramming.
Definition of Aurora exception classes.
DoubleDispatcher(bool symmetric=true)
Constructor.
Result call(Parameter arg1, Parameter arg2) const
Dispatches the key of arg1 and arg2 and invokes the corresponding function.
~DoubleDispatcher()
Destructor.
void bind(const Id1 &identifier1, const Id2 &identifier2, Fn function)
Registers a function bound to a specific key.
Non-copyable base class.
Definition: NonCopyable.hpp:42
Class that is able to perform dynamic dispatch on multiple functions with two parameters.
Definition: DoubleDispatcher.hpp:119
Configuration header of the library.
FunctionParam< Signature, 0 >::Type Parameter
Function parameter type denoting the object used for the dispatch.
Definition: DoubleDispatcher.hpp:130
Class template aurora::DispatchTraits.
DoubleDispatcher & operator=(DoubleDispatcher &&source)
Move assignment operator.
FunctionParam< Signature, 2 >::Type UserData
Addition parameter for user data, only useful if Signature contains more than 2 parameters.
Definition: DoubleDispatcher.hpp:134
Class aurora::NonCopyable.
void fallback(std::function< Signature > function)
Registers a fallback function.
FunctionResult< Signature >::Type Result
Function return type.
Definition: DoubleDispatcher.hpp:126
Definition: DispatchTraits.hpp:39