fix a few things with new signal code

This commit is contained in:
Mark Tiefenbruck 2008-09-20 23:46:23 -07:00
parent ab8b21d18c
commit 4c11204716
2 changed files with 25 additions and 5 deletions

View file

@ -24,6 +24,7 @@
#include "Slot.hh"
#include <list>
#include <map>
#include <vector>
namespace FbTk {
@ -45,6 +46,8 @@ public:
typedef Iterator SlotID;
typedef SlotList::const_iterator ConstIterator;
virtual ~SignalHolder() { }
/// Remove a specific slot \c id from this signal
void disconnect(SlotID slotIt) {
m_slots.erase( slotIt );
@ -78,6 +81,8 @@ class Signal0: public SignalHolder {
public:
typedef Slot0<ReturnType> SlotType;
virtual ~Signal0() { }
void emit() {
for ( Iterator it = begin(); it != end(); ++it ) {
static_cast<SlotType&>(*it)();
@ -96,6 +101,8 @@ class Signal1: public SignalHolder {
public:
typedef Slot1<ReturnType, Arg1> SlotType;
virtual ~Signal1() { }
void emit(Arg1 arg) {
for ( Iterator it = begin(); it != end(); ++it ) {
static_cast<SlotType&>(*it)(arg);
@ -114,6 +121,8 @@ class Signal2: public SignalHolder {
public:
typedef Slot2<ReturnType, Arg1, Arg2> SlotType;
virtual ~Signal2() { }
void emit(Arg1 arg1, Arg2 arg2) {
for ( Iterator it = begin(); it != end(); ++it ) {
static_cast<SlotType&>(*it)(arg1, arg2);
@ -131,6 +140,8 @@ class Signal3: public SignalHolder {
public:
typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
virtual ~Signal3() { }
void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
for ( Iterator it = begin(); it != end(); ++it ) {
static_cast<SlotType&>(*it)(arg1, arg2, arg3);
@ -180,16 +191,15 @@ public:
class SignalTracker {
public:
/// Internal type, do not use.
typedef std::list< std::pair< SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID > > Connections;
typedef std::map<SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID> Connections;
typedef Connections::iterator TrackID; ///< \c ID type for join/leave.
~SignalTracker() {
virtual ~SignalTracker() {
// disconnect all connections
for ( Connections::iterator conIt = m_connections.begin();
conIt != m_connections.end(); ) {
conIt != m_connections.end(); ++conIt)
conIt->first->disconnect( conIt->second );
conIt = m_connections.erase( conIt );
}
m_connections.clear();
}
/// Starts tracking a signal.
@ -207,6 +217,13 @@ public:
m_connections.erase(id);
}
/// Leave tracking for a signal
/// @param sig the signal to leave
template <typename Signal>
void leave(Signal &sig) {
m_connections.erase(&sig);
}
private:
/// holds all connections to different signals and slots.
Connections m_connections;

View file

@ -429,6 +429,9 @@ Fluxbox::~Fluxbox() {
// destroy screens (after others, as they may do screen things)
while (!m_screen_list.empty()) {
// this needs to be done before the signal is destroyed
leave( m_screen_list.back()->workspaceCountSig() );
delete m_screen_list.back();
m_screen_list.pop_back();
}