Boost Users :
From: shyamemani (shyamemani_at_[hidden])
Date: 2003-08-26 18:36:59
I hate writing code in mailing list but here is a sample of what I
want to do. I have a tree data strucutre class which fires event and
each event has some different parameters that are passed to it. What
I want to illustrate is that by calling one register function I get
access to three events. In boost.signal this would require that the
client call the connect for each event. Is this a good application
for this library?
In deisgn like this, the programmar knows exactly which function
to look for when an event is fired. Hence it is easy to find the
execution block. Since the compiler looks for the pure virtual
functions it enforces that these be implemented. In boost::function
or boost.signal the name of the function is not fixed hence takes
virtual void node_added(Node* _node) = 0;
virtual void node_deleted(const char* _path) = 0;
virtual void node_accessed(Node* _node,int _change) = 0;
/* some variables*/
std:: set<TreeEvent*> listeners; /*set used to ensure unique
void register(TreeEvent* _listen); /*add to listener set*/
void unregister(TreeEvent* _listen); /*remove from listener
void add_node(const char* _path,Node* _node)
/* do something
iterate through event set and call node_added function.*/
/* similar implementation for remove_node and get_node calling
node_deleted and node_accessed functions on each element in
the listeners set */
class MyClient : public TreeEvent
/* some other stuff */
/* implement pure virtual functions */
/*...lot of stuff for tree creation...*/
/* this one call gives me access to all the events */
/* other things */
the class MyClient now gets all the events and can do what it wants
in response to these events.
--- In Boost-Users_at_[hidden], "Edward Diener" <eddielee_at_t...>
> Douglas Gregor wrote:
> > On Tuesday 26 August 2003 02:56 pm, shyamemani wrote:
> >> When I mentioned the performance cost I was comparing two
> >> techniques. a) Using call back interfaces and b) using
> >> boost::functions. As Douglas mentioned that if the operator is
> >> inlined, the performance of boost::function will be better since
> >> virtual functions cannot be inlined by the compiler and I agree
> >> him.
> > I think we have a little communication confusion, and I think
> > fault.
> > What do you mean by "call back interfaces"? Function pointers?
> > Hardcoded
> > calls to particular routines? Or are by "interfaces" are you
> > about
> > something akin to Java's interfaces?
> > Calling through a boost::function will incur essentially the same
> > overhead as
> > calling through a virtual function.
> >> But with interfaces I can define multiple functions in
> >> register to recieve multiple events. Use of this in
> >> would require calling register multiple times. I think I am
> >> considering wrong application of the library.
> > boost::function doesn't support multiple events. That's why we
> > Boost.Signals built on top of boost::function.
> This has reminded to ask you:
> Is there a reason Boost.Signals wasn't submitted for TR1 approval
> the worked involved doing so by writing up the necessary submittal
form ? I
> would very much like to see the C++ standard library adopt a common
> handling interface, whether through a library such as yours or an
> to the language ( such as Borland's __closure pointer ). Handling
> a common way, and especially allowing both events and handlers (
> slots ) to be free of specific class limitations, will move C++
> to a modern paradigm which I find invaluable in using the language.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net