[Home]Function

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

FAQ for boost::function

Function Library - Mail Thread Summary

Generalizing C-style Callbacks

---

Would someone like to provide a one line (ok, maybe two) summary of what someone might use this library for? The tutorial implied it was likely to be used replacing virtual functions. Anything else?

  proxy_id_t tagfsmMgr::registerProxy(IfsmProxy?* P,[RegistrationPriority t]? prio)
  {
    if(NULL!=P)
      {
	P->setManager(this);
	boost::function<void ([EventHdr t]?*)> f=bind1st(mem_fun(&IfsmProxy?::handleEvent), P);
        //Now? use the binding f as a normal function call
	dispatcher.connect(prio,f);
       //..... rest of the code....
 }//</if>
}

With this as Proxy method:

  void tagfsmProxy::handleEvent([EventHdr t]?* evt){
  //..... rest of the code
}

And here is the signature for dispatcher in this code snippet for information:

 typedef boost::signal<void ([EventHdr t]?*)> Dispatcher_t;
 Dispatcher_t dispatcher;

boost::function enables you to make a C-like callback call to method fsmProxy::handleEvent (bound to variable f) as if it were a plain C function.Hope it helps.


BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited August 17, 2008 10:58 am (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers