// // Created by Dawid Drozd aka Gelldur on 18/10/16. // #pragma once #include #include "EventBus.h" namespace Dexode { class EventCollector { public: EventCollector(const std::shared_ptr& bus); EventCollector(EventBus* bus); EventCollector(EventCollector const& other); EventCollector(EventCollector&& other); ~EventCollector(); EventCollector& operator=(EventCollector const& other); EventCollector& operator=(EventCollector&& other); /** * Register listener for event. * * @tparam Event - type you want to listen for * @param callback - your callback to handle event */ template void listen(const std::function& callback) { if (!callback || !_bus) { return;//Skip such things } if (_token == 0) { _token = _bus->listen(callback); } else { _bus->listen(_token, callback); } } void unlistenAll(); /** * @tparam Event - type you want to unlisten. @see Notiier::listen */ template void unlisten() { if (_bus) { _bus->unlisten(_token); } } private: int _token = 0; std::shared_ptr _bus; }; }