On Tuesday 10 December 2002 04:48 am, Malcolm Smith wrote:
I read Boost.Function info and it sounds like part of the solution.
Is there a way of associating a key with a container of *different* boost.Function's ?
Not directly. How are you planning to invoke functions in this map? You gave the example:
// I know this is not valid code but it explains what I'm after typedef std::map
StateFunctions; void Method1(void); int Method2(TCustomClass &MyClass);
StateFunctions[1] = Method1; StateFunctions[2] = Method2;
My question is: do you really want the parameter lists to be different for StateFunctions[1] and StateFunctions[2], meaning that when calling you might need something like:
foo = StateFunctions[x]; if (foo has arity zero) foo(); else if (foo has arity one with type TCustomClass) foo(herClass); else if (...) etc. etc.
?
Or are all the parameters to the functors known when they are put into the StateFunctions map? Then what you really want is something that achieves
desired effect:
StateFunctions[1] = Method1; StateFunctions[2] = something that calls Method2 with parameter herClass
If it's the latter case, you've run into the classic Boost.Bind/Boost.Function (or Boost.Lambda/Boost.Function, if your compiler can handle it) scenario :)
Then you want:
typedef std::map
> StateFunctions; StateFunctions[1] = &Method1; StateFunctions[2] = boost::bind(&Method2, boost::ref(&herClass));
int x = something(); StateFunctions[x](); // call the appropriate state function
If it's the former case (different parameter lists), then there's no
Doug,
I think I can deal with the latter, I'll read boost.bind now and see if it
fits the bill.
If worst comes to worst I could always create a polymorphic 'payload' to go
with the state information. Speed is not an issue so I'm not worried about
the overheads. The functions being called send socket requests to a digital
video recorder over a WAN and they take longer to perform than my app would
ever perform.
Thanks for the info....more reading.
--
Malcolm Smith
MJ Freelancing- http://www.mjfreelancing.com
Software Protection for C++Builder
Borland Technology Partner
"Douglas Gregor"
"Boost way" to do this that I know of.
Doug
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/