Boost logo

Boost :

From: Andreas Huber (ah2003_at_[hidden])
Date: 2004-05-01 12:26:05

Max Khesin <MKhesin <at>> writes:

> I am refactoring code that looks something like this:
> if (op == LN::FILTER_IN || op == LN::FILTER_NOT_IN)
> {
> where += handle_set_operation(column, type, format, op,
> expr_set);
> }
> else if (op == LN::FILTER_RANGE)
> {
> where += handle_range_operation(column, type, format, op,
> expr_set);
> }
> else if (op == LN::FILTER_NULL || op == LN::FILTER_NOT_NULL)
> {
> where += handle_null_operation(column, op);
> }
> ...

I assume that you somewhere have a switch/case or multiple if/else if
implementing dispatch on "where", before the above code is executed. If so,
then this looks like the implementation of a state machine.

> This would obviously be handled better with a map of some sort (has to map
> int to function). The problem here is that some functions have more
> arguments than others, precluding the possibility of uniform type for the
> function value of the map. I cannot just go and change the function sig to
> include dummy values ('cause it's a dumb idea). This situation made me think
> of boost.function/boost.bind, which allows to effectively shorten the
> function parameter list by binding some of the args.

It seems that would be possible, but I think (given that I'm right about the
state machine nature of your code) there are better ways to implement this.
You might want to have a look at boost::fsm:

Docs only:

Code, examples and docs zipped:



Boost list run by bdawes at, gregod at, cpdaniel at, john at