diff --git a/include/gamepad/event_handler.hpp b/include/gamepad/event_handler.hpp index 6bdc188..d4660a0 100644 --- a/include/gamepad/event_handler.hpp +++ b/include/gamepad/event_handler.hpp @@ -12,44 +12,46 @@ namespace Gamepad { class MonotonicCounter { - template friend class EventHandler; - static uint32_t next_value() { - static std::atomic counter = 0; - return ++counter; - } + template friend class EventHandler; + + static uint32_t next_value() { + static std::atomic counter = 0; + return ++counter; + } }; -template -class EventHandler { +template class EventHandler { public: - using Listener = std::function; - uint32_t add_listener(Listener func) { - std::lock_guard lock(mutex); - uint32_t id = MonotonicCounter::next_value(); - listeners.emplace(id, std::move(func)); - return id; - } - bool remove_listener(uint32_t id) { - std::lock_guard lock(mutex); - if(listeners.find(id) == listeners.end()) { - TODO("change handling maybe?") - return false; + using Listener = std::function; + + uint32_t add_listener(Listener func) { + std::lock_guard lock(mutex); + uint32_t id = MonotonicCounter::next_value(); + listeners.emplace(id, std::move(func)); + return id; + } + + bool remove_listener(uint32_t id) { + std::lock_guard lock(mutex); + if (listeners.find(id) == listeners.end()) { + TODO("change handling maybe?") + return false; + } + listeners.erase(id); + return true; + } + + bool is_empty() { + std::lock_guard lock(mutex); + return listeners.empty(); } - listeners.erase(id); - return true; - } - bool is_empty() { - std::lock_guard lock(mutex); - return listeners.empty(); - } - void fire(Args... args) { - std::lock_guard lock(mutex); - for(auto listener : listeners) { - listener.second(args...); + + void fire(Args... args) { + std::lock_guard lock(mutex); + for (auto listener : listeners) { listener.second(args...); } } - } private: - std::map listeners; - pros::Mutex mutex; + std::map listeners; + pros::Mutex mutex; }; -} \ No newline at end of file +} // namespace Gamepad \ No newline at end of file