#include <dispatch.h>
Collaboration diagram for Dv::Util::Dispatcher< Application, Input, Value >:
Public Types | |
typedef bool(Application::* | Handler )(Input &input, const Value &value) |
Handler type. | |
Static Public Member Functions | |
bool | handle (Application &a, Input &input, const Value &value) |
Main handler function. | |
Static Public Attributes | |
Entry | table [] |
Actual dispatch table. |
The framework assumes that there are two objects:
Input input; // represents input for application Application application; // represents application
The Application class has a number of handler functions
Application::handle_value_1(Input& input, const Value& value) Application::handle_value_2(Input& input, const Value& value)
The class template below makes it easy to dispatch to the correct handler-function, based on the given value.
To use, an instance should define Dispatcher<Application,Input,Value>::table as in the example below.
typedef std::string Value; Dispatcher<Application,Input,Value>::Entry Dispatcher<Application,Input,Value>::table[] = { { "", &Application::default_handler }, { "a", &Application::handle_a }, { "b", &Application::handle_b }, { "c", &Application::handle_c }, { "", 0 } // sentinel };
The Application class could then define an Application::main function as follows.
class Application { public: bool main(Input& input, const Value& value) { return Dispatcher<Application,Input,Value>::handle(*this, input, value); } };
Definition at line 56 of file dispatch.h.
|
Handler type. Definition at line 59 of file dispatch.h. |
|
Main handler function. It will use value to dispatch a call to the appropriate handler function. An actual example can be found in test-dispatch.C in the source directory.
References Dv::Util::Dispatcher< Application, Input, Value >::Entry::h, Dv::Util::Dispatcher< Application, Input, Value >::Entry::key, and Dv::Util::Dispatcher< Application, Input, Value >::table. |
|
Actual dispatch table. Define as in the example below. Dispatcher<Application,Input,std::string>::Entry Dispatcher<Application,Input,std::string>::table[] = { { "", &Application::default_handler }, { "a", &Application::handle_a }, { "b", &Application::handle_b }, { "c", &Application::handle_c }, { "", 0 } // sentinel Referenced by Dv::Util::Dispatcher< Application, Input, Value >::handle(). |
dvutil-0.13.15 | [30 December, 2004] |