#include <ObjectDispatcher.h> [code]
Inheritance diagram for Utils::ObjectDispatcher< DispatchBase, Sender >:

This is a helper class that provides typeid() based object dispatching.
Object dispatching is an alternative to the double-dispatching technique used in the Visitor Pattern. ObjectDispatcher is extremely helpful if you want to avoid switching on type codes just in order to cast and forward an object to the appropriate handler.
Template parameters:
ObjectDispatcher supports three types of handlers:
A handler could be a non-member function, static class function, or a class member function.
The first parameter of catch-all and not-handled handler functions must be of type const DispatchBase &. The first parameter of type handler function must be const DispatchBaseDerived &.
Each of the handlers might have a second parameter of type Sender *. This second parameter would contain the address of the object that invoked the dispatch() method. This value could also be 0 if the sender chose not to give its address.
Once you call the dispatch() method, it will invoke all handlers corresponding registered handlers (see dispatch() for more details).
Definition at line 77 of file ObjectDispatcher.h.
Public Types | |
| typedef Callable< void(const DispatchBase &)> | DispatchBaseHandler |
| typedef Callable< void(const DispatchBase &, Sender *) | DispatchBaseSenderHandler ) |
Public Member Functions | |
| ObjectDispatcher () | |
| Default constructor. | |
| ~ObjectDispatcher () | |
| Destructor. Frees all allocated memory. | |
| void | registerCatchAllHandler (const DispatchBaseHandler &handler) |
| Register a non-member/static-member function as a catch-all handler. | |
| void | registerCatchAllHandler (const DispatchBaseSenderHandler &handler) |
| Register a member function as a catch-all handler. | |
| template<typename T> | |
| void | registerTypeHandler (const Callable< void(const T &)> &handler) |
| Register a non-member/static-member function as type handler. | |
| template<typename T> | |
| void | registerTypeHandler (const Callable< void(const T &, Sender *)> &handler) |
| Register a member function as type handler. | |
| template<typename T> | |
| void | unregisterTypeHandler (const Callable< void(const T &)> &handler) |
| Unregister a non-member/static-member function as type handler. | |
| template<typename T> | |
| void | unregisterTypeHandler (const Callable< void(const T &, Sender *)> &handler) |
| Unregister a member function as type handler. | |
| void | registerNotHandledHandler (const DispatchBaseHandler &handler) |
| Register a non-member/static-member function as type handler. | |
| void | registerNotHandledHandler (const DispatchBaseSenderHandler &handler) |
| Register a member function as type handler. | |
| bool | dispatch (const DispatchBase &object, Sender *sender=0) |
| Dispatch object to the corresponding registered handlers. | |
Private Member Functions | |
| void | doRegisterCatchAllHandler (Handler *handler) |
| Helper to register handler as a type handler for T. | |
| template<typename T> | |
| void | doRegisterHandler (Handler *handler) |
| Helper to register handler as a type handler for T. | |
| template<typename T> | |
| void | doUnregisterHandler (Handler *handler) |
| Helper to register handler as a type handler for T. | |
| void | doRegisterNotHandledHandler (Handler *handler) |
| Helper to register handler as a type handler for T. | |
| void | dispatchToCatchAllHandlers (const DispatchBase &object, Sender *sender) |
| Helper to dispatch to all the catch-all registered handlers. | |
| bool | dispatchToTypeHandlers (const DispatchBase &object, Sender *sender) |
| Helper to dispatch to all type handlers matching typeid (object). | |
| void | dispatchToNotHandledHandlers (const DispatchBase &object, Sender *sender) |
| Helper to dispatch to all not-handled handlers. | |
Private Attributes | |
| QList< Handler * > | catchAllHandlers |
| QMultiMap< const std::type_info *, Handler * > | handlers |
| QList< Handler * > | notHandledHandlers |
Classes | |
| struct | Handler |
| Interface to a Handler wrapper. More... | |
| class | TypeHandler |
| class | TypeHandlerWithSender |
|
|||||
|
Definition at line 80 of file ObjectDispatcher.h. |
|
|||||
|
Definition at line 82 of file ObjectDispatcher.h. |
|
|||||||||
|
Default constructor.
Definition at line 85 of file ObjectDispatcher.h. |
|
|||||||||
|
Destructor. Frees all allocated memory.
Definition at line 91 of file ObjectDispatcher.h. |
|
||||||||||||||||
|
Dispatch object to the corresponding registered handlers.
Definition at line 177 of file ObjectDispatcher.h. |
|
||||||||||||||||
|
Helper to dispatch to all the catch-all registered handlers.
Definition at line 226 of file ObjectDispatcher.h. |
|
||||||||||||||||
|
Helper to dispatch to all not-handled handlers.
Definition at line 253 of file ObjectDispatcher.h. |
|
||||||||||||||||
|
Helper to dispatch to all type handlers matching typeid (object). Gets the list of all handlers already registered for the runtime type of object and iterates in reverse order because the most recently inserted handlers are first in the list. We want the order in which the handlers are called to be the order in which the handlers are registered. Definition at line 240 of file ObjectDispatcher.h. |
|
||||||||||
|
Helper to register handler as a type handler for T.
Definition at line 190 of file ObjectDispatcher.h. |
|
||||||||||||||
|
Helper to register handler as a type handler for T.
Definition at line 197 of file ObjectDispatcher.h. |
|
||||||||||
|
Helper to register handler as a type handler for T.
Definition at line 220 of file ObjectDispatcher.h. |
|
||||||||||||||
|
Helper to register handler as a type handler for T.
Definition at line 205 of file ObjectDispatcher.h. |
|
||||||||||
|
Register a member function as a catch-all handler.
Definition at line 110 of file ObjectDispatcher.h. |
|
||||||||||
|
Register a non-member/static-member function as a catch-all handler.
Definition at line 103 of file ObjectDispatcher.h. |
|
||||||||||
|
Register a member function as type handler.
Definition at line 156 of file ObjectDispatcher.h. |
|
||||||||||
|
Register a non-member/static-member function as type handler.
Definition at line 149 of file ObjectDispatcher.h. |
|
||||||||||||||
|
Register a member function as type handler.
Definition at line 126 of file ObjectDispatcher.h. |
|
||||||||||||||
|
Register a non-member/static-member function as type handler.
Definition at line 118 of file ObjectDispatcher.h. |
|
||||||||||||||
|
Unregister a member function as type handler.
Definition at line 142 of file ObjectDispatcher.h. |
|
||||||||||||||
|
Unregister a non-member/static-member function as type handler.
Definition at line 134 of file ObjectDispatcher.h. |
|
|||||
|
Definition at line 309 of file ObjectDispatcher.h. |
|
|||||
|
Definition at line 310 of file ObjectDispatcher.h. |
|
|||||
|
Definition at line 311 of file ObjectDispatcher.h. |