Skip to content

Commit

Permalink
GUI2: remove every matching signal from an event queue when disconnec…
Browse files Browse the repository at this point in the history
…ting

I'm not exactly sure if this is a desired change. It does allow the use of std::list::remove_if to simplify
the code a bit, but if first-only removal should be kept I can change it.
  • Loading branch information
Vultraz committed May 1, 2017
1 parent 890177d commit 81eb23c
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions src/gui/core/event/dispatcher.hpp
Expand Up @@ -681,54 +681,35 @@ class dispatcher
const queue_position position,
const T& signal)
{
/*
* The function doesn't differentiate between front and back
* position so fall down from front to back.
signal_type<T>& signal_queue = queue[event];

/* The function doesn't differentiate between front and back position so fall
* down from front to back.
*
* NOTE: This used to only remove the first signal of matching target type.
* That behavior could be restored in the future if needed.
* - vultraz 5/2/2017
*/
switch(position) {
case front_pre_child:
case back_pre_child: {
signal_type<T>& signal_queue = queue[event];
for(typename std::list<T>::iterator itor
= signal_queue.pre_child.begin();
itor != signal_queue.pre_child.end();
++itor) {

if(signal.target_type() == itor->target_type()) {
signal_queue.pre_child.erase(itor);
return;
}
}
signal_queue.pre_child.remove_if(
[&signal](T& element) { return signal.target_type() == element.target_type(); }
);
} break;

case front_child:
case back_child: {
signal_type<T>& signal_queue = queue[event];
for(typename std::list<T>::iterator itor
= signal_queue.child.begin();
itor != signal_queue.child.end();
++itor) {

if(signal.target_type() == itor->target_type()) {
signal_queue.child.erase(itor);
return;
}
}
signal_queue.child.remove_if(
[&signal](T& element) { return signal.target_type() == element.target_type(); }
);
} break;

case front_post_child:
case back_post_child: {
signal_type<T>& signal_queue = queue[event];
for(typename std::list<T>::iterator itor
= signal_queue.post_child.begin();
itor != signal_queue.post_child.end();
++itor) {

if(signal.target_type() == itor->target_type()) {
signal_queue.post_child.erase(itor);
return;
}
}
signal_queue.post_child.remove_if(
[&signal](T& element) { return signal.target_type() == element.target_type(); }
);
} break;
}
}
Expand Down

0 comments on commit 81eb23c

Please sign in to comment.