1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-10-27 05:23:39 -04:00
polybar/include/events/signal_receiver.hpp
Patrick Ziegler d5be8cad97
Add compiler warning for missing override specifier (#2341)
* build: Add -Wsuggest-override

We should always use the override specifier when overriding virtual
functions. This helps prevent errors when a subclass tries to create a
function with the same name as a virtual function in a super-class but
with a different purpose.

* clang-format

* Upload logs on failure

* Add override to unsupported.hpp

* cmake: Make -Wsuggest-override flag conditional
2021-01-04 10:38:43 +01:00

52 lines
1.2 KiB
C++

#pragma once
#include <map>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include "common.hpp"
POLYBAR_NS
class signal_receiver_interface {
public:
using prio = int;
using prio_map = std::multimap<prio, signal_receiver_interface*>;
virtual ~signal_receiver_interface() {}
virtual prio priority() const = 0;
template <typename Signal>
bool on(const Signal& signal);
};
template <typename Signal>
class signal_receiver_impl {
public:
virtual ~signal_receiver_impl() {}
virtual bool on(const Signal&) = 0;
};
template <typename Signal>
bool signal_receiver_interface::on(const Signal& s) {
auto event_sink = dynamic_cast<signal_receiver_impl<Signal>*>(this);
if (event_sink != nullptr && event_sink->on(s)) {
return true;
} else {
return false;
}
}
template <int Priority, typename Signal, typename... Signals>
class signal_receiver : public signal_receiver_interface,
public signal_receiver_impl<Signal>,
public signal_receiver_impl<Signals>... {
public:
prio priority() const override {
return Priority;
}
};
using signal_receivers_t = std::unordered_map<std::type_index, signal_receiver_interface::prio_map>;
POLYBAR_NS_END