From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2006-10-18 13:46:18
On 10/19/06, Caleb Epstein <caleb.epstein_at_[hidden]> wrote:
> I think this question was raised before, and I'm not sure if it was
> answered in a meaningful way so I'll ask it again.
> What is the difference between your dispatcher and a std::map<Key,
> boost::function<Prototype> >?
Okay, I think I answered this before, but I'll try answering it again. :-)
First, the dispatcher allows you to define a stateful validation
function/functor for the indexes used to access the dispatcher. That
means, you can check and make sure that the index being used to access
the registered functions are valid -- this is usually domain specific,
and left as a template parameter to the dispatcher. There are examples
in the documentation that comes with the downloadable file(s).
Second, the dispatcher allows you to define a stateful routing
strategy for "manipulating" the indexes as they are used to refer to
the elements in the dispatcher. There's an example as to how you can
use the routing strategy to implement a simple round-robin "hash".
This functionality is usually domain specific, and is left as a
template parameter to the dispatcher.
The third difference is that it allows you a reusable, generic, and
type-safe way of scheduling index invocations using the invoker
interface. This allows you to do something like:
typedef boost::dispatch::dispatcher<void(int, int), std::string> dispatcher_t
// ... register your handlers here, or elsewhere ...
dispatcher_t::invoke_(dispatcher_instance)(param1, param2) << "first"
<< "second" << "third";
Typical usage is for implementing a factory, using it for scheduling
load distribution on a pool of threads, etc.
A simple std::map<IndexType, boost::function<Prototype> > does not
give you the above three facilities.
I hope this answers your question.
-- Dean Michael C. Berris C++ Software Architect Orange and Bronze Software Labs, Ltd. Co. web: http://software.orangeandbronze.com/ email: dean_at_[hidden] mobile: +63 928 7291459 phone: +63 2 8943415 other: +1 408 4049532 blogs: http://mikhailberis.blogspot.com http://3w-agility.blogspot.com http://cplusplus-soup.blogspot.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk