I'm no expert on these type of libraries but I have come to the point where I must find time to study *this* library more. I have a current project that requires some re-writes in specific areas and I'm hoping Boost will be able to make this job easier. Is there something in boost that will ease the implementation of a state-machine type functor. As an example, I am using a 3rd party C++Builder component that makes socket connections to hardware devices. I need to modify the connection code so 'what needs to be done after a connection success/failure' is handled in the appropriate events. The thing is, this connection event can be called due to connections in other areas of the application under different conditions. If I can implement a state based connection handler then I could re-direct the calls to the appropriate (alternate) event. As an example (I'm only just starting to read up on the STL), I know I could use a std::map to hold state values as the key and call the appropriate handler via a pointer to a function in .second - what I'm hoping is there is a library that allows for unrestricted function signatures (different parameter lists) to be associated with state values. To make this clearer // I know this is not valid code but it explains what I'm after typedef std::map<int, *pf(...)> StateFunctions; void Method1(void); int Method2(TCustomClass &MyClass); StateFunctions[1] = Method1; StateFunctions[2] = Method2; Does this make sense to anyone ? I've probably got all the terminology wrong so feel free to correct me where ever applicable. Thanks in advance. -- Malcolm Smith MJ Freelancing- http://www.mjfreelancing.com Software Protection for C++Builder Borland Technology Partner
I'm no expert on these type of libraries but I have come to the point where I must find time to study *this* library more.
I have a current project that requires some re-writes in specific areas and I'm hoping Boost will be able to make this job easier.
Is there something in boost that will ease the implementation of a state-machine type functor.
As an example, I am using a 3rd party C++Builder component that makes socket connections to hardware devices. I need to modify the connection code so 'what needs to be done after a connection success/failure' is handled in
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 ? -- Malcolm Smith MJ Freelancing- http://www.mjfreelancing.com Software Protection for C++Builder Borland Technology Partner "Malcolm Smith" <yg-boost-users@m.gmane.org> wrote in message news:at2uqb$5an$1@main.gmane.org... the
appropriate events. The thing is, this connection event can be called due to connections in other areas of the application under different conditions.
If I can implement a state based connection handler then I could re-direct the calls to the appropriate (alternate) event.
As an example (I'm only just starting to read up on the STL), I know I could use a std::map to hold state values as the key and call the appropriate handler via a pointer to a function in .second - what I'm hoping is there is a library that allows for unrestricted function signatures (different parameter lists) to be associated with state values.
To make this clearer
// I know this is not valid code but it explains what I'm after typedef std::map<int, *pf(...)> StateFunctions;
void Method1(void); int Method2(TCustomClass &MyClass);
StateFunctions[1] = Method1; StateFunctions[2] = Method2;
Does this make sense to anyone ? I've probably got all the terminology wrong so feel free to correct me where ever applicable.
Thanks in advance.
-- Malcolm Smith MJ Freelancing- http://www.mjfreelancing.com Software Protection for C++Builder Borland Technology Partner
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/
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<int, *pf(...)> 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 the 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<int, boost::function<void()> > 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 direct "Boost way" to do this that I know of. Doug
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<int, *pf(...)> 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<int, boost::function<void()> > 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" <gregod@cs.rpi.edu> wrote in message news:200212100856.34752.gregod@cs.rpi.edu... the direct
"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/
participants (2)
-
Douglas Gregor
-
Malcolm Smith