|
Boost Users : |
From: svanechel (svanechel_at_[hidden])
Date: 2003-04-11 05:24:49
Hi,
Is there a reason why siganls aren't copyable? As far as I can tell
signal base derives from noncopyable, but it references its
implementation using shared_ptr. So I'm guessing in theory a signal
is perfectly copyable. I must admit I came to this conclusion by
briefly looking at the code, so I might be completely wrong.
I want to store signals into a vector of function<void()>'s, together
with bound arguments, to capture events and replay them later.
Something similar to (simplified):
class recorder
{
public:
// this is the handler for some event
// it is connected to another signal
void some_event( int i)
{
events_.push_back( bind( ev, i ) );
}
void replay()
{
vector< function<void()> >::const_iterator itr = events_.begin();
while ( itr != events_.end() )
{
(*itr)();
++itr;
}
}
signal<void(int)> ev;
private:
vector< function<void()> > events_;
};
recorder rec;
// connect the recorder to the signals is uses
...
// now replay the events
rec.ev.connect( some_handler );
rec.replay();
The example above may no be entirely correct since I'm coding this
directly without running it through a compiler, but I hope the intent
is clear.
If I remove the derivation from noncopyable from signal_base, a sigal
can be assigned to a function, although I haven't tested it yet to
see if it actually works (currently I do not have something I can
start testing with).
Is it safe to remove the noncopyable base class? If so can it be done
in the next release of the boost distribution as well?
Thanks in advance,
Sven Van Echelpoel
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