Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2006-10-19 05:20:43


Hi Matthew!

On 10/19/06, Matthew Herrmann <matthew.herrmann_at_[hidden]> wrote:
> Hi Michael,

Dean is fine. :-)

>
> It looks like the rival for your library is not a switch statement or an
> if-else statement, but a hash_map. In your rationale, you should make
> clear what your library can do that the following construct cannot:
>

[snipped code]

I think I should improve on the documentation. :-) It's in the TODO now. :D

>
> From my reading, the only difference is that hash map's operator[] will
> not throw in the case where an element is not found.
>

There's that, and there's also the capability of doing index
validation and index routing/manipulation using a state-ful public
member variable for the validator and the router. An instance of the
validator type (which can be provided as a template parameter) and the
router type (which can be provided as a template parameter as well)
can be left for the user to manipulate and use based on the situation.
An example would be:

struct my_routing_strategy {
  int operator() (int i) const {
    return i % 10;
  };
};

struct my_validation_strategy {
  bool operator() (int i) const {
    return i < 9 ? false : true ;
  };
};

void function(int value) {
  std::cout << value << std::endl;
};

// ...
dispatcher<void(int), int, my_validation_strategy, my_routing_strategy> d;
// d.validator is accessible
// d.router is accessible
d[10] = &function;
d[9] = &function; // will throw

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