29 #ifndef AURORA_SINGLEDISPATCHER_HPP
30 #define AURORA_SINGLEDISPATCHER_HPP
38 #include <unordered_map>
115 template <
typename Signature,
class Traits = RttiDispatchTraits<Signature, 1>>
123 typedef typename FunctionResult<Signature>::Type
Result;
127 typedef typename FunctionParam<Signature, 0>::Type
Parameter;
131 typedef typename FunctionParam<Signature, 1>::Type
UserData;
138 static_assert(std::is_pointer<Parameter>::value || std::is_lvalue_reference<Parameter>::value,
139 "Function parameter must be a pointer or reference.");
167 template <
typename Id,
typename Fn>
168 void bind(
const Id& identifier, Fn
function);
177 Result
call(Parameter arg)
const;
189 Result
call(Parameter arg, UserData data)
const;
196 void fallback(std::function<Signature>
function);
202 typedef typename Traits::Key Key;
203 typedef std::function<Signature> BaseFunction;
204 typedef std::unordered_map<Key, BaseFunction> FnMap;
211 BaseFunction mFallback;
218 #include <Aurora/Dispatch/Detail/SingleDispatcher.inl>
219 #endif // AURORA_SINGLEDISPATCHER_HPP
SingleDispatcher & operator=(SingleDispatcher &&source)
Move assignment operator.
void bind(const Id &identifier, Fn function)
Registers a function bound to a specific key.
Utilities for template metaprogramming.
FunctionResult< Signature >::Type Result
Function return type.
Definition: SingleDispatcher.hpp:123
Result call(Parameter arg) const
Dispatches the key of arg and invokes the corresponding function.
Definition of Aurora exception classes.
FunctionParam< Signature, 1 >::Type UserData
Addition parameter for user data, only useful if Signature contains more than 1 parameter.
Definition: SingleDispatcher.hpp:131
Non-copyable base class.
Definition: NonCopyable.hpp:42
Configuration header of the library.
Class template aurora::DispatchTraits.
~SingleDispatcher()
Destructor.
void fallback(std::function< Signature > function)
Registers a fallback function.
SingleDispatcher()
Default constructor.
Class that is able to perform dynamic dispatch on multiple functions with one parameter.
Definition: SingleDispatcher.hpp:116
Class aurora::NonCopyable.
FunctionParam< Signature, 0 >::Type Parameter
Function parameter type denoting the object used for the dispatch.
Definition: SingleDispatcher.hpp:127
Definition: DispatchTraits.hpp:39