From: Miguel Tadeu (m_tadeu_at_[hidden])
Date: 2007-10-19 11:00:35
Ok, a little bit of explanation...
Let's follow a real life example that occured to me a while ago. I wrote a
piece of software that received a buffer through rs232. I had to interpret
that buffer and, depending on the opcode I had to call the right function.
Lest's just say there were about 100 different opcodes. Their destination
were to several different objects.
Solution at that time:
- read opcode from the buffer
- creat a big switch/case to call the right object::function
Switch/case are apopriate if the opcode is not a string, in which case
you'll just have 100 if/else if clauses.
- [begining]register each function in a container
- [on each communication]pack each parameter in a vector<any>
- call get the function by it's opcode(number/string/whatever) and call it
Miguel Tadeu wrote:
> I wrote a small library that attempts to abstract function calls. This
> proved me useful in the following situations:
> - when I need to find a callback function( lots of if's or big switch )
> - when I deal with communication frames with opcodes
> - several other libraries use callback mechanisms( i.e: dbus )
> and brings these advantages:
> - cleaner code( main objective )
> - makes possible to isolate class implementations from the low level call
> - makes it easy to implement a polymorphism like mechanism
> Currentely, it's in beta phase. If enough interest is shown, there is
> surely room for minor improvements.
> Miguel Tadeu
> Unsubscribe & other changes:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk