Re: [boost] Runtime Dynamic Dispatch (boost-dispatch)

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Dean Michael Berris Sent: Thursday, October 19, 2006 10:46 AM To: boost@lists.boost.org Subject: Re: [boost] Runtime Dynamic Dispatch (boost-dispatch)
Hi Sohail,
On 10/20/06, Sohail Somani <s.somani@fincad.com> wrote:
Is it not possible at all to have a d(1,2,3) interface?
With the tuples, you are specifying the interface already.
I'm not sure what you mean by `d(1, 2, 3)'... If you have something like:
void function(int a, int b, int c) { // do something with a, b, and c };
dispatcher<void(int, int, int)> d; d[0] = &function; d[0](1, 2, 3);
Then definitely that's possible.
It would be more natural.
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?

Hi Sohail, On 10/20/06, Sohail Somani <s.somani@fincad.com> 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@orangeandbronze.com 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
participants (2)
-
Dean Michael Berris
-
Sohail Somani