Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This file is part of w3c - wwwcam.
- // w3c is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- // w3c is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- // You should have received a copy of the GNU General Public License
- // along with w3c. If not, see <http://www.gnu.org/licenses/>.
- //
- // (C) Copyright 2015 by Sebastian Büttner <sebastian.buettner@iem.thm.de>
- #ifndef HELPER_EVENT_H
- #define HELPER_EVENT_H
- #include <forward_list>
- template<typename... event_arg_types>
- class event;
- template<typename... event_arg_types>
- class event_handlers {
- friend class event;
- public:
- using handler_type = void()(event_arg_types...);
- event_handlers& operator+=(handler_type &&handler)
- {
- add(std::forward<handler_type>(handler));
- }
- event_handlers& add(handler_type &&handler)
- {
- m_handlers.push_front(handler);
- }
- private:
- std::forward_list<handler_type> m_handlers;
- };
- template<typename... event_arg_types>
- class event {
- public:
- void operator()(event_arg_types... event_args)
- {
- for (auto handler : m_handlers.m_handlers)
- handler(std::forward<event_arg_types...>(event_args...));
- }
- event_handlers<event_arg_types...> handlers() const
- {
- return m_handlers;
- }
- private:
- event_handlers<event_arg_types...> m_handlers;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement