Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2006-10-19 23:00:23


Hi Sohail,

On 10/20/06, Sohail Somani <s.somani_at_[hidden]> wrote:
> >
> > Can you elaborate on what you mean so that I don't
> > misunderstand what you mean?
>
> What I mean is overloading operator() with the types of the tuple so you
> can call the dispatcher like a function.
>
> Does that clarify?

A bit, though I'm still not so sure I understand. I'l' try to explain
why the dispatcher doesn't have that feature:

First, the dispatcher is a means of accessing functions using an
index, much like how you would use a map. It is definitely possible to
have an overload which calls all the registered methods, however that
defeats the purpose of a dispatch based on an index. If what you need
is something that will call all the registered functions, you should
be using Boost.Signal where you essentially have a publish-subscribe
model for the functions.

Second, the goal of the dispatcher is to allow routing to a function
based on an index. This mechanism is similar to what a switch()
statement provides albeit more flexible and more extensible. You can
define validation and routing strategies to allow you to customize how
you deal with the index used to access the registered functions.

Third, if you notice, the index may or may not be associated with the
function prototype used to define the functions registered to the
dispatcher. This decoupling of the index from the function arguments
is the reason behind:

dispatcher<void(double), std::string> d;
d["hello"] = &function_1;
d["world"] = &function_2;
std::string input_string;
double input_double;
std::cin >> input_string >> input_double;
d[input_string](input_double);

You can see more concrete example usage in the unit-test included in
the package for more details. The documentation (though incomplete)
should be able to give more light regarding how the dispatcher can be
used.

HTH

-- 
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