From 5e8429d5ee8e2196e6da2dd5c3585d53edd180aa Mon Sep 17 00:00:00 2001 From: stickz Date: Sun, 12 Jan 2025 09:40:41 -0500 Subject: [PATCH] cleanup: Remove/replace functional_fun.h functions Reference: https://github.com/rakshasa/rtorrent/pull/1343 --- rtorrent/Makefile.am | 1 - rtorrent/rak/functional_fun.h | 656 -------------------------- rtorrent/src/command_ui.cc | 1 - rtorrent/src/control.cc | 2 +- rtorrent/src/core/view.cc | 1 - rtorrent/src/rpc/command_scheduler.cc | 2 +- rtorrent/src/rpc/command_scheduler.h | 6 +- rtorrent/src/rpc/scgi.cc | 5 +- rtorrent/src/rpc/scgi.h | 4 +- 9 files changed, 8 insertions(+), 670 deletions(-) delete mode 100644 rtorrent/rak/functional_fun.h diff --git a/rtorrent/Makefile.am b/rtorrent/Makefile.am index f610487f6..5b18a3f24 100644 --- a/rtorrent/Makefile.am +++ b/rtorrent/Makefile.am @@ -11,7 +11,6 @@ EXTRA_DIST= \ rak/error_number.h \ rak/file_stat.h \ rak/functional.h \ - rak/functional_fun.h \ rak/path.h \ rak/partial_queue.h \ rak/priority_queue.h \ diff --git a/rtorrent/rak/functional_fun.h b/rtorrent/rak/functional_fun.h deleted file mode 100644 index f793db53f..000000000 --- a/rtorrent/rak/functional_fun.h +++ /dev/null @@ -1,656 +0,0 @@ -// rak - Rakshasa's toolbox -// Copyright (C) 2005-2007, Jari Sundell -// -// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -// This file contains functors that wrap function pointers and member -// function pointers. -// -// 'fn' functors are polymorphic and derives from 'rak::function' and -// thus is less strict about types, this adds the cost of calling a -// virtual function. -// -// 'fun' functors are non-polymorphic and thus cheaper, but requires -// the target object's type in the functor's template arguments. -// -// This should be replaced with TR1 stuff when it becomes widely -// available. At the moment it behaves like std::auto_ptr, so be -// careful when copying. - -#ifndef RAK_FUNCTIONAL_FUN_H -#define RAK_FUNCTIONAL_FUN_H - -#include -#include -#include lt_tr1_functional -#include lt_tr1_memory - -namespace rak { - -template -class function_base0 { -public: - virtual ~function_base0() {} - - virtual Result operator () () = 0; -}; - -template -class function_base1 : public std::unary_function { -public: - virtual ~function_base1() {} - - virtual Result operator () (Arg1 arg1) = 0; -}; - -template -class function_base2 : public std::binary_function { -public: - virtual ~function_base2() {} - - virtual Result operator () (Arg1 arg1, Arg2 arg2) = 0; -}; - -template -class function_base3 { -public: - virtual ~function_base3() {} - - virtual Result operator () (Arg1 arg1, Arg2 arg2, Arg3 arg3) = 0; -}; - -template -class function0 { -public: - typedef Result result_type; - typedef function_base0 base_type; - - bool is_valid() const { return m_base.get() != NULL; } - - void set(base_type* base) { m_base = std::shared_ptr(base); } - base_type* release() { return m_base.release(); } - - Result operator () () { return (*m_base)(); } - -private: - std::shared_ptr m_base; -}; - -template -class function1 { -public: - typedef Result result_type; - typedef function_base1 base_type; - - bool is_valid() const { return m_base.get() != NULL; } - - void set(base_type* base) { m_base = std::shared_ptr(base); } - base_type* release() { return m_base.release(); } - - Result operator () (Arg1 arg1) { return (*m_base)(arg1); } - -private: - std::shared_ptr m_base; -}; - -template -class function2 { -public: - typedef Result result_type; - typedef function_base2 base_type; - - bool is_valid() const { return m_base.get() != NULL; } - - void set(base_type* base) { m_base = std::shared_ptr(base); } - base_type* release() { return m_base.release(); } - - Result operator () (Arg1 arg1, Arg2 arg2) { return (*m_base)(arg1, arg2); } - -private: - std::shared_ptr m_base; -}; - -template -class function2 { -public: - typedef Result result_type; - typedef function_base1 base_type; - - bool is_valid() const { return m_base.get() != NULL; } - - void set(base_type* base) { m_base = std::shared_ptr(base); } - base_type* release() { return m_base.release(); } - - Result operator () (Arg2 arg2) { return (*m_base)(arg2); } - - template - Result operator () (Discard discard, Arg2 arg2) { return (*m_base)(arg2); } - -private: - std::shared_ptr m_base; -}; - -template -class function3 { -public: - typedef Result result_type; - typedef function_base3 base_type; - - bool is_valid() const { return m_base.get() != NULL; } - - void set(base_type* base) { m_base = std::shared_ptr(base); } - base_type* release() { return m_base.release(); } - - Result operator () (Arg1 arg1, Arg2 arg2, Arg3 arg3) { return (*m_base)(arg1, arg2, arg3); } - -private: - std::shared_ptr m_base; -}; - -template -class ptr_fn0_t : public function_base0 { -public: - typedef Result (*Func)(); - - ptr_fn0_t(Func func) : m_func(func) {} - virtual ~ptr_fn0_t() {} - - virtual Result operator () () { return m_func(); } - -private: - Func m_func; -}; - -template -class ptr_fn1_t : public function_base1 { -public: - typedef Result (*Func)(Arg1); - - ptr_fn1_t(Func func) : m_func(func) {} - virtual ~ptr_fn1_t() {} - - virtual Result operator () (Arg1 arg1) { return m_func(arg1); } - -private: - Func m_func; -}; - -template -class ptr_fn2_t : public function_base2 { -public: - typedef Result (*Func)(Arg1, Arg2); - - ptr_fn2_t(Func func) : m_func(func) {} - virtual ~ptr_fn2_t() {} - - virtual Result operator () (Arg1 arg1, Arg2 arg2) { return m_func(arg1, arg2); } - -private: - Func m_func; -}; - -template -class mem_fn0_t : public function_base0 { -public: - typedef Result (Object::*Func)(); - - mem_fn0_t(Object* object, Func func) : m_object(object), m_func(func) {} - virtual ~mem_fn0_t() {} - - virtual Result operator () () { return (m_object->*m_func)(); } - -private: - Object* m_object; - Func m_func; -}; - -template -class mem_fn1_t : public function_base1 { -public: - typedef Result (Object::*Func)(Arg1); - - mem_fn1_t(Object* object, Func func) : m_object(object), m_func(func) {} - virtual ~mem_fn1_t() {} - - virtual Result operator () (Arg1 arg1) { return (m_object->*m_func)(arg1); } - -private: - Object* m_object; - Func m_func; -}; - -template -class mem_fn3_t : public function_base3 { -public: - typedef Result (Object::*Func)(Arg1, Arg2, Arg3); - - mem_fn3_t(Object* object, Func func) : m_object(object), m_func(func) {} - virtual ~mem_fn3_t() {} - - virtual Result operator () (Arg1 arg1, Arg2 arg2, Arg3 arg3) { return (m_object->*m_func)(arg1, arg2, arg3); } - -private: - Object* m_object; - Func m_func; -}; - -template -class mem_fn2_t : public function_base2 { -public: - typedef Result (Object::*Func)(Arg1, Arg2); - - mem_fn2_t(Object* object, Func func) : m_object(object), m_func(func) {} - virtual ~mem_fn2_t() {} - - virtual Result operator () (Arg1 arg1, Arg2 arg2) { return (m_object->*m_func)(arg1, arg2); } - -private: - Object* m_object; - Func m_func; -}; - -template -class const_mem_fn0_t : public function_base0 { -public: - typedef Result (Object::*Func)() const; - - const_mem_fn0_t(const Object* object, Func func) : m_object(object), m_func(func) {} - virtual ~const_mem_fn0_t() {} - - virtual Result operator () () { return (m_object->*m_func)(); } - -private: - const Object* m_object; - Func m_func; -}; - -template -class const_mem_fn1_t : public function_base1 { -public: - typedef Result (Object::*Func)(Arg1) const; - - const_mem_fn1_t(const Object* object, Func func) : m_object(object), m_func(func) {} - virtual ~const_mem_fn1_t() {} - - virtual Result operator () (Arg1 arg1) { return (m_object->*m_func)(arg1); } - -private: - const Object* m_object; - Func m_func; -}; - -// Unary functor with a bound argument. -template -class mem_fn0_b1_t : public function_base0 { -public: - typedef Result (Object::*Func)(Arg1); - - mem_fn0_b1_t(Object* object, Func func, const Arg1 arg1) : m_object(object), m_func(func), m_arg1(arg1) {} - virtual ~mem_fn0_b1_t() {} - - virtual Result operator () () { return (m_object->*m_func)(m_arg1); } - -private: - Object* m_object; - Func m_func; - const Arg1 m_arg1; -}; - -template -class mem_fn1_b1_t : public function_base1 { -public: - typedef Result (Object::*Func)(Arg1, Arg2); - - mem_fn1_b1_t(Object* object, Func func, const Arg1 arg1) : m_object(object), m_func(func), m_arg1(arg1) {} - virtual ~mem_fn1_b1_t() {} - - virtual Result operator () (const Arg2 arg2) { return (m_object->*m_func)(m_arg1, arg2); } - -private: - Object* m_object; - Func m_func; - const Arg1 m_arg1; -}; - -template -class mem_fn1_b2_t : public function_base1 { -public: - typedef Result (Object::*Func)(Arg1, Arg2); - - mem_fn1_b2_t(Object* object, Func func, const Arg2 arg2) : m_object(object), m_func(func), m_arg2(arg2) {} - virtual ~mem_fn1_b2_t() {} - - virtual Result operator () (const Arg1 arg1) { return (m_object->*m_func)(arg1, m_arg2); } - -private: - Object* m_object; - Func m_func; - const Arg2 m_arg2; -}; - -template -class ptr_fn0_b1_t : public function_base0 { -public: - typedef Result (*Func)(Arg1); - - ptr_fn0_b1_t(Func func, const Arg1 arg1) : m_func(func), m_arg1(arg1) {} - virtual ~ptr_fn0_b1_t() {} - - virtual Result operator () () { return m_func(m_arg1); } - -private: - Func m_func; - Arg1 m_arg1; -}; - -template -class ptr_fn1_b1_t : public function_base1 { -public: - typedef Result (*Func)(Arg1, Arg2); - - ptr_fn1_b1_t(Func func, const Arg1 arg1) : m_func(func), m_arg1(arg1) {} - virtual ~ptr_fn1_b1_t() {} - - virtual Result operator () (Arg2 arg2) { return m_func(m_arg1, arg2); } - -private: - Func m_func; - Arg1 m_arg1; -}; - -template -class ptr_fn2_b1_t : public function_base2 { -public: - typedef Result (*Func)(Arg1, Arg2, Arg3); - - ptr_fn2_b1_t(Func func, const Arg1 arg1) : m_func(func), m_arg1(arg1) {} - virtual ~ptr_fn2_b1_t() {} - - virtual Result operator () (Arg2 arg2, Arg3 arg3) { return m_func(m_arg1, arg2, arg3); } - -private: - Func m_func; - Arg1 m_arg1; -}; - -template -class ftor_fn1_t : public function_base1 { -public: - typedef typename Ftor::result_type result_type; - typedef typename Ftor::argument_type argument_type; - - ftor_fn1_t(Ftor ftor) : m_ftor(ftor) {} - virtual ~ftor_fn1_t() {} - - virtual result_type operator () (argument_type arg1) { return m_ftor(arg1); } - -private: - Ftor m_ftor; -}; - -template -class ftor_fn2_t : public function_base2 { -public: - typedef typename Ftor::result_type result_type; - typedef typename Ftor::first_argument_type first_argument_type; - typedef typename Ftor::second_argument_type second_argument_type; - - ftor_fn2_t(Ftor ftor) : m_ftor(ftor) {} - virtual ~ftor_fn2_t() {} - - virtual result_type operator () (first_argument_type arg1, second_argument_type arg2) { return m_ftor(arg1, arg2); } - -private: - Ftor m_ftor; -}; - -template -class value_fn0_t : public function_base0 { -public: - value_fn0_t(const Result& val) : m_value(val) {} - - virtual Result operator () () { return m_value; } - -private: - Result m_value; -}; - -template -class convert_fn0_t : public function_base0 { -public: - typedef function0 src_type; - - convert_fn0_t(typename src_type::base_type* object) { m_object.set(object); } - virtual ~convert_fn0_t() {} - - virtual Result operator () () { - return m_object(); - } - -private: - src_type m_object; -}; - -template -class convert_fn1_t : public function_base1 { -public: - typedef function1 src_type; - - convert_fn1_t(typename src_type::base_type* object) { m_object.set(object); } - virtual ~convert_fn1_t() {} - - virtual Result operator () (Arg1 arg1) { - return m_object(arg1); - } - -private: - src_type m_object; -}; - -template -class convert_fn2_t : public function_base2 { -public: - typedef function2 src_type; - - convert_fn2_t(typename src_type::base_type* object) { m_object.set(object); } - virtual ~convert_fn2_t() {} - - virtual Result operator () (Arg1 arg1, Arg2 arg2) { - return m_object(arg1, arg2); - } - -private: - src_type m_object; -}; - -template -inline function_base0* -ptr_fn(Result (*func)()) { - return new ptr_fn0_t(func); -} - -template -inline function_base1* -ptr_fn(Result (*func)(Arg1)) { - return new ptr_fn1_t(func); -} - -template -inline function_base2* -ptr_fn(Result (*func)(Arg1, Arg2)) { - return new ptr_fn2_t(func); -} - -template -inline function_base0* -mem_fn(Object* object, Result (Object::*func)()) { - return new mem_fn0_t(object, func); -} - -template -inline function_base1* -mem_fn(Object* object, Result (Object::*func)(Arg1)) { - return new mem_fn1_t(object, func); -} - -template -inline function_base2* -mem_fn(Object* object, Result (Object::*func)(Arg1, Arg2)) { - return new mem_fn2_t(object, func); -} - -template -inline function_base3* -mem_fn(Object* object, Result (Object::*func)(Arg1, Arg2, Arg3)) { - return new mem_fn3_t(object, func); -} - -template -inline function_base0* -mem_fn(const Object* object, Result (Object::*func)() const) { - return new const_mem_fn0_t(object, func); -} - -template -inline function_base1* -mem_fn(const Object* object, Result (Object::*func)(Arg1) const) { - return new const_mem_fn1_t(object, func); -} - -template -inline function_base0* -bind_mem_fn(Object* object, Result (Object::*func)(Arg1), const Arg1 arg1) { - return new mem_fn0_b1_t(object, func, arg1); -} - -template -inline function_base1* -bind_mem_fn(Object* object, Result (Object::*func)(Arg1, Arg2), const Arg1 arg1) { - return new mem_fn1_b1_t(object, func, arg1); -} - -template -inline function_base1* -bind2_mem_fn(Object* object, Result (Object::*func)(Arg1, Arg2), const Arg2 arg2) { - return new mem_fn1_b2_t(object, func, arg2); -} - -template -inline function_base0* -bind_ptr_fn(Result (*func)(Arg1), const Arg1 arg1) { - return new ptr_fn0_b1_t(func, arg1); -} - -template -inline function_base1* -bind_ptr_fn(Result (*func)(Arg1, Arg2), const Arg1 arg1) { - return new ptr_fn1_b1_t(func, arg1); -} - -template -inline function_base2* -bind_ptr_fn(Result (*func)(Arg1, Arg2, Arg3), const Arg1 arg1) { - return new ptr_fn2_b1_t(func, arg1); -} - -template -inline function_base1* -ftor_fn1(Ftor ftor) { - return new ftor_fn1_t(ftor); -} - -template -inline function_base2* -ftor_fn2(Ftor ftor) { - return new ftor_fn2_t(ftor); -} - -template -inline function_base0* -value_fn(const Result& val) { - return new value_fn0_t(val); -} - -template -struct equal_types_t { - typedef A first_type; - typedef B second_type; - - const static int result = 0; -}; - -template -struct equal_types_t { - typedef A first_type; - typedef A second_type; - - const static int result = 1; -}; - -template -inline function_base0* -convert_fn(function_base0* src) { - if (equal_types_t, function_base0 >::result) - // The pointer cast never gets done if the types are different, - // but needs to be here to pleasant the compiler. - return reinterpret_cast, function_base0 >::first_type*>(src); - else - return new convert_fn0_t(src); -} - -template -inline function_base1* -convert_fn(function_base1* src) { - if (equal_types_t, function_base1 >::result) - // The pointer cast never gets done if the types are different, - // but needs to be here to pleasant the compiler. - return reinterpret_cast, function_base1 >::first_type*>(src); - else - return new convert_fn1_t(src); -} - -template -inline function_base2* -convert_fn(function_base2* src) { - if (equal_types_t, function_base2 >::result) - // The pointer cast never gets done if the types are different, - // but needs to be here to pleasant the compiler. - return reinterpret_cast, function_base2 >::first_type*>(src); - else - return new convert_fn2_t(src); -} - -} - -#endif diff --git a/rtorrent/src/command_ui.cc b/rtorrent/src/command_ui.cc index 38ebfd79d..5911606b7 100644 --- a/rtorrent/src/command_ui.cc +++ b/rtorrent/src/command_ui.cc @@ -43,7 +43,6 @@ #include #include -#include #include #include "core/manager.h" diff --git a/rtorrent/src/control.cc b/rtorrent/src/control.cc index 89a7be071..a1815b672 100644 --- a/rtorrent/src/control.cc +++ b/rtorrent/src/control.cc @@ -82,7 +82,7 @@ Control::Control() : m_taskShutdown.slot() = std::bind(&Control::handle_shutdown, this); - m_commandScheduler->set_slot_error_message(rak::mem_fn(m_core, &core::Manager::push_log_std)); + m_commandScheduler->set_slot_error_message([this](const std::string& msg) { m_core->push_log_std(msg); }); } Control::~Control() { diff --git a/rtorrent/src/core/view.cc b/rtorrent/src/core/view.cc index bfdeac359..ac5b0d1d8 100644 --- a/rtorrent/src/core/view.cc +++ b/rtorrent/src/core/view.cc @@ -39,7 +39,6 @@ #include #include #include -#include #include #include diff --git a/rtorrent/src/rpc/command_scheduler.cc b/rtorrent/src/rpc/command_scheduler.cc index 40be3679f..c0861c5c2 100644 --- a/rtorrent/src/rpc/command_scheduler.cc +++ b/rtorrent/src/rpc/command_scheduler.cc @@ -100,7 +100,7 @@ CommandScheduler::call_item(value_type item) { rpc::call_object(item->command()); } catch (torrent::input_error& e) { - if (m_slotErrorMessage.is_valid()) + if (m_slotErrorMessage) m_slotErrorMessage("Scheduled command failed: " + item->key() + ": " + e.what()); } diff --git a/rtorrent/src/rpc/command_scheduler.h b/rtorrent/src/rpc/command_scheduler.h index d2bcef209..b1eca3543 100644 --- a/rtorrent/src/rpc/command_scheduler.h +++ b/rtorrent/src/rpc/command_scheduler.h @@ -40,7 +40,7 @@ #include #include #include -#include +#include namespace torrent { class Object; @@ -52,7 +52,7 @@ class CommandSchedulerItem; class CommandScheduler : public std::vector { public: - typedef rak::function1 SlotString; + typedef std::function SlotString; typedef std::pair Time; typedef std::vector base_type; @@ -63,7 +63,7 @@ class CommandScheduler : public std::vector { CommandScheduler() {} ~CommandScheduler(); - void set_slot_error_message(SlotString::base_type* s) { m_slotErrorMessage.set(s); } + void set_slot_error_message(SlotString s) { m_slotErrorMessage = s; } // slot_error_message or something. diff --git a/rtorrent/src/rpc/scgi.cc b/rtorrent/src/rpc/scgi.cc index f992718ca..0579d5f5a 100644 --- a/rtorrent/src/rpc/scgi.cc +++ b/rtorrent/src/rpc/scgi.cc @@ -166,13 +166,10 @@ SCgi::event_error() { bool SCgi::receive_call(SCgiTask* task, const char* buffer, uint32_t length) { - slot_write slotWrite; - slotWrite.set(rak::mem_fn(task, &SCgiTask::receive_write)); - torrent::thread_base::acquire_global_lock(); torrent::main_thread()->interrupt(); - bool result = xmlrpc.process(buffer, length, slotWrite); + bool result = xmlrpc.process(buffer, length, [task](const char* b, uint32_t l) { return task->receive_write(b, l); }); torrent::thread_base::release_global_lock(); diff --git a/rtorrent/src/rpc/scgi.h b/rtorrent/src/rpc/scgi.h index 4b1a0e44b..090f59606 100644 --- a/rtorrent/src/rpc/scgi.h +++ b/rtorrent/src/rpc/scgi.h @@ -38,7 +38,7 @@ #define RTORRENT_RPC_SCGI_H #include -#include +#include #include #include "scgi_task.h" @@ -51,7 +51,7 @@ namespace rpc { class lt_cacheline_aligned SCgi : public torrent::Event { public: - typedef rak::function2 slot_write; + typedef std::function slot_write; static const int max_tasks = 100;