Compare commits

..

2 Commits

Author SHA1 Message Date
Michele Caini
9761b6e14a updated version 2017-12-29 18:29:38 +01:00
Michele Caini
cb49910ed2 allow attaching listeners at any time, allow removing current listener 2017-12-29 18:25:49 +01:00
4 changed files with 18 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ endif()
# Project configuration
#
project(entt VERSION 2.4.0)
project(entt VERSION 2.4.1)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)

View File

@@ -181,7 +181,9 @@ public:
const auto buf = buffer(mode);
mode = !mode;
for(auto &&wrapper: wrappers) {
for(auto pos = wrappers.size(); pos > decltype(pos){0}; --pos) {
auto &wrapper = wrappers[pos-1];
if(wrapper) {
wrapper->publish(buf);
}

View File

@@ -229,7 +229,8 @@ public:
* @param args Arguments to use to invoke listeners.
*/
void publish(Args... args) {
for(auto &&call: calls) {
for(auto pos = calls.size(); pos > size_type{0}; --pos) {
auto &call = calls[pos-1];
call.second(call.first, args...);
}
}
@@ -242,7 +243,9 @@ public:
collector_type collect(Args... args) {
collector_type collector;
for(auto &&call: calls) {
for(auto pos = calls.size(); pos > size_type{0}; --pos) {
auto &call = calls[pos-1];
if(!this->invoke(collector, call.second, call.first, args...)) {
break;
}

View File

@@ -167,11 +167,17 @@ public:
* @param args Arguments to use to invoke listeners.
*/
void publish(Args... args) {
for(auto it = calls.rbegin(), end = calls.rend(); it != end; it++) {
if(!(it->second)(it->first, args...)) {
calls.erase(std::next(it).base());
std::vector<call_type> next;
for(auto pos = calls.size(); pos > size_type{0}; --pos) {
auto &call = calls[pos-1];
if((call.second)(call.first, args...)) {
next.push_back(call);
}
}
calls.swap(next);
}
/**