From fd0b79e97dbd6ec7c2dc0a6e67384815961a1c3e Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 13 Oct 2019 05:58:53 +0200 Subject: [PATCH] utility-event: Remove unused event handler --- source/utility/utility-event.cpp | 105 --------------------------- source/utility/utility-event.hpp | 118 ------------------------------- 2 files changed, 223 deletions(-) delete mode 100644 source/utility/utility-event.cpp delete mode 100644 source/utility/utility-event.hpp diff --git a/source/utility/utility-event.cpp b/source/utility/utility-event.cpp deleted file mode 100644 index 11fe682..0000000 --- a/source/utility/utility-event.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Modern effects for a modern Streamer - * Copyright (C) 2018 Michael Fabian Dirks - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "utility-event.hpp" - -utility::event::event() -{ - on.add = std::make_shared(); - on.remove = std::make_shared(); - on.empty = std::make_shared(); -} - -utility::event::~event() -{ - clear(); - on.add.reset(); - on.remove.reset(); - on.empty.reset(); -} - -size_t utility::event::add(listener_t callback) -{ - _listeners.push_back(callback); - - { - event_args_t args; - args.emplace("event", this); - args.emplace("listener", &callback); - on.add->call(args); - } - - return _listeners.size(); -} - -size_t utility::event::remove(listener_t callback) -{ - _listeners.remove(callback); - - { - event_args_t args; - args.emplace("event", this); - args.emplace("listener", &callback); - on.remove->call(args); - } - - if (_listeners.empty()) { - event_args_t args; - args.emplace("event", this); - on.empty->call(args); - } - - return _listeners.size(); -} - -size_t utility::event::count() -{ - return _listeners.size(); -} - -bool utility::event::empty() -{ - return _listeners.empty(); -} - -void utility::event::clear() -{ - _listeners.clear(); - event_args_t args; - args.emplace("event", this); - on.empty->call(args); -} - -size_t utility::event::call(event_args_t& arguments) -{ - size_t idx = 0; - for (auto const& listener : _listeners) { - /*if (listener.first.expired()) { - // Lifeline has expired, so remove it. - _listeners.remove(listener); - continue; - }*/ - - //if (listener.second(listener.first, arguments)) { -// break; - // } - idx++; - } - return idx; -} diff --git a/source/utility/utility-event.hpp b/source/utility/utility-event.hpp deleted file mode 100644 index 8e9c89b..0000000 --- a/source/utility/utility-event.hpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Modern effects for a modern Streamer - * Copyright (C) 2018 Michael Fabian Dirks - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef OBS_STREAM_EFFECTS_UTILITY_EVENT_CPP -#define OBS_STREAM_EFFECTS_UTILITY_EVENT_CPP -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace utility { - typedef std::weak_ptr lifeline_t; - typedef std::map event_args_t; -#define D_EVENT_FUNC_T void(std::weak_ptr, event_args_t) - typedef std::function event_cb_t; - - struct event_pair { - lifeline_t lifeline; - event_cb_t callback; - - event_pair(lifeline_t _lifeline, event_cb_t _callback) - { - lifeline = _lifeline; - callback = _callback; - } - - bool operator==(const event_pair& rhs) - { - return (!lifeline.owner_before(rhs.lifeline) && !rhs.lifeline.owner_before(lifeline)) - && (lifeline.lock() == rhs.lifeline.lock()) - && (callback.target() == rhs.callback.target()); - } - }; - - typedef event_pair listener_t; - - class event { - std::list _listeners; - - public: - event(); - virtual ~event(); - - size_t add(listener_t listener); - - inline event operator+=(listener_t listener) - { - add(listener); - return *this; - } - - size_t remove(listener_t listener); - - inline event operator-=(listener_t listener) - { - remove(listener); - return *this; - } - - size_t count(); - - bool empty(); - - inline operator bool() - { - return !this->empty(); - } - - void clear(); - - size_t call(event_args_t& arguments); - - inline size_t operator()(event_args_t& arguments) - { - return call(arguments); - } - - inline size_t call() - { - event_args_t args{}; - return call(args); - } - - inline size_t operator()() - { - return call(); - } - - public: - struct { - std::shared_ptr add; - std::shared_ptr remove; - std::shared_ptr empty; - } on; - }; -} // namespace utility - -#endif OBS_STREAM_EFFECTS_UTILITY_EVENT_CPP