added Emitter::clearAll

This commit is contained in:
Michele Caini 2016-07-31 19:22:14 +02:00
parent aa20079537
commit cf65a0a65f

View File

@ -20,6 +20,7 @@ class Emitter {
struct BaseHandler {
virtual ~BaseHandler() noexcept = default;
virtual bool empty() const noexcept = 0;
virtual void clear() noexcept = 0;
};
template<typename E>
@ -33,6 +34,11 @@ class Emitter {
return onceL.empty() && onL.empty();
}
void clear() noexcept override {
onceL.clear();
onL.clear();
}
Connection once(Listener f) {
auto conn = onceL.insert(onceL.cbegin(), std::move(f));
return { onceL, std::move(conn) };
@ -47,11 +53,6 @@ class Emitter {
conn.first.erase(conn.second);
}
void clear() noexcept {
onceL.clear();
onL.clear();
}
void publish(const E &event, T &ref) {
for(auto &&listener: onceL) { listener(event, ref); }
for(auto &&listener: onL) { listener(event, ref); }
@ -122,6 +123,12 @@ public:
handler<E>().clear();
}
void clearAll() noexcept {
for(auto &&h: handlers) {
h->clear();
}
}
bool empty() const noexcept {
bool empty = true;