Skip to content

Commit

Permalink
rTorrent c++17 additions
Browse files Browse the repository at this point in the history
  • Loading branch information
stickz committed Jan 11, 2025
1 parent 5e3e629 commit 883de91
Show file tree
Hide file tree
Showing 25 changed files with 42 additions and 59 deletions.
1 change: 0 additions & 1 deletion rtorrent/rak/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#define RAK_ALGORITHM_H

#include <algorithm>
#include <functional>
#include <limits>

namespace rak {
Expand Down
1 change: 0 additions & 1 deletion rtorrent/rak/priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#define RAK_PRIORITY_QUEUE_H

#include <algorithm>
#include <functional>
#include <vector>

namespace rak {
Expand Down
2 changes: 1 addition & 1 deletion rtorrent/rak/priority_queue_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#ifndef RAK_PRIORITY_QUEUE_DEFAULT_H
#define RAK_PRIORITY_QUEUE_DEFAULT_H

#include lt_tr1_functional
#include <rak/allocators.h>
#include <rak/functional.h>
#include <rak/priority_queue.h>
#include <rak/timer.h>

Expand Down
1 change: 0 additions & 1 deletion rtorrent/rak/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <sys/types.h>

#include <algorithm>
#include <functional>
#include <string>
#include <list>

Expand Down
1 change: 0 additions & 1 deletion rtorrent/rak/string_manip.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <cctype>
#include <climits>
#include <cstdlib>
#include <functional>
#include <iterator>
#include <locale>
#include <random>
Expand Down
2 changes: 1 addition & 1 deletion rtorrent/src/command_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ apply_close_low_diskspace(int64_t arg) {
bool closed = false;
core::Manager::DListItr itr = downloadList->begin();

while ((itr = std::find_if(itr, downloadList->end(), std::mem_fun(&core::Download::is_downloading)))
while ((itr = std::find_if(itr, downloadList->end(), std::mem_fn(&core::Download::is_downloading)))
!= downloadList->end()) {
if ((*itr)->file_list()->free_diskspace() < (uint64_t)arg) {
downloadList->close(*itr);
Expand Down
2 changes: 1 addition & 1 deletion rtorrent/src/command_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ torrent::Object
apply_enable_trackers(int64_t arg) {
for (core::Manager::DListItr itr = control->core()->download_list()->begin(), last = control->core()->download_list()->end(); itr != last; ++itr) {
std::for_each((*itr)->tracker_list()->begin(), (*itr)->tracker_list()->end(),
arg ? std::mem_fun(&torrent::Tracker::enable) : std::mem_fun(&torrent::Tracker::disable));
arg ? std::mem_fn(&torrent::Tracker::enable) : std::mem_fn(&torrent::Tracker::disable));

if (arg && !rpc::call_command_value("trackers.use_udp"))
(*itr)->enable_udp_trackers(false);
Expand Down
2 changes: 1 addition & 1 deletion rtorrent/src/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(std::bind(&core::Manager::push_log_std, m_core, std::placeholders::_1));
}

Control::~Control() {
Expand Down
5 changes: 2 additions & 3 deletions rtorrent/src/core/curl_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <curl/multi.h>
#include <torrent/exceptions.h>

#include "rak/functional.h"
#include "curl_get.h"
#include "curl_socket.h"
#include "curl_stack.h"
Expand Down Expand Up @@ -147,7 +146,7 @@ CurlStack::process_done_handle() {
throw torrent::internal_error("CurlStack::receive_action() msg->msg != CURLMSG_DONE.");

if (msg->data.result == CURLE_COULDNT_RESOLVE_HOST) {
iterator itr = std::find_if(begin(), end(), rak::equal(msg->easy_handle, std::mem_fn(&CurlGet::handle)));
iterator itr = std::find_if(begin(), end(), [msg](CurlGet* cg) { return msg->easy_handle == cg->handle(); });

if (itr == end())
throw torrent::internal_error("Could not find CurlGet when calling CurlStack::receive_action.");
Expand All @@ -162,7 +161,7 @@ CurlStack::process_done_handle() {

void
CurlStack::transfer_done(void* handle, const char* msg) {
iterator itr = std::find_if(begin(), end(), rak::equal(handle, std::mem_fn(&CurlGet::handle)));
iterator itr = std::find_if(begin(), end(), [handle](CurlGet* cg) { return handle == cg->handle(); });

if (itr == end())
throw torrent::internal_error("Could not find CurlGet with the right easy_handle.");
Expand Down
1 change: 0 additions & 1 deletion rtorrent/src/core/download.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <list>
#include <rak/file_stat.h>
#include <rak/functional.h>
#include <rak/path.h>
#include <torrent/exceptions.h>
#include <torrent/rate.h>
Expand Down
17 changes: 8 additions & 9 deletions rtorrent/src/core/download_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <rak/functional.h>
#include <rak/string_manip.h>
#include <torrent/data/file.h>
#include <torrent/utils/resume.h>
Expand Down Expand Up @@ -80,15 +79,15 @@ DownloadList::check_contains(Download* d) {

void
DownloadList::clear() {
std::for_each(begin(), end(), std::bind1st(std::mem_fn(&DownloadList::close), this));
std::for_each(begin(), end(), rak::call_delete<Download>());
std::for_each(begin(), end(), [&](Download* d) { close(d); });
std::for_each(begin(), end(), [](Download* d) { delete d; });

base_type::clear();
}

void
DownloadList::session_save() {
unsigned int c = std::count_if(begin(), end(), std::bind1st(std::mem_fn(&DownloadStore::save_resume), control->core()->download_store()));
unsigned int c = std::count_if(begin(), end(), [&](Download* d) { return control->core()->download_store()->save_resume(d); });

if (c != size())
lt_log_print(torrent::LOG_ERROR, "Failed to save session torrents.");
Expand All @@ -99,7 +98,7 @@ DownloadList::session_save() {

DownloadList::iterator
DownloadList::find(const torrent::HashString& hash) {
return std::find_if(begin(), end(), rak::equal(hash, rak::on(std::mem_fn(&Download::info), std::mem_fn(&torrent::DownloadInfo::hash))));
return std::find_if(begin(), end(), [hash](Download* d) { return hash == d->info()->hash(); });
}

DownloadList::iterator
Expand All @@ -109,7 +108,7 @@ DownloadList::find_hex(const char* hash) {
for (torrent::HashString::iterator itr = key.begin(), last = key.end(); itr != last; itr++, hash += 2)
*itr = (rak::hexchar_to_value(*hash) << 4) + rak::hexchar_to_value(*(hash + 1));

return std::find_if(begin(), end(), rak::equal(key, rak::on(std::mem_fn(&Download::info), std::mem_fn(&torrent::DownloadInfo::hash))));
return std::find_if(begin(), end(), [key](Download* d) { return key == d->info()->hash(); });
}

Download*
Expand Down Expand Up @@ -187,8 +186,8 @@ DownloadList::insert(Download* download) {

// This needs to be separated into two different calls to ensure
// the download remains in the view.
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fn(&View::insert), download));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fn(&View::filter_download), download));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind(&View::insert, std::placeholders::_1, download));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind(&View::filter_download, std::placeholders::_1, download));

DL_TRIGGER_EVENT(*itr, "event.download.inserted");

Expand Down Expand Up @@ -221,7 +220,7 @@ DownloadList::erase(iterator itr) {
control->core()->download_store()->remove(*itr);

DL_TRIGGER_EVENT(*itr, "event.download.erased");
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fn(&View::erase), *itr));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind(&View::erase, std::placeholders::_1, *itr));

torrent::download_remove(*(*itr)->download());
delete *itr;
Expand Down
1 change: 0 additions & 1 deletion rtorrent/src/core/http_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <sstream>
#include <torrent/http.h>

#include "rak/functional.h"
#include "http_queue.h"
#include "curl_get.h"

Expand Down
5 changes: 1 addition & 4 deletions rtorrent/src/core/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
#include "config.h"

#include <algorithm>
#include <functional>
#include <rak/functional.h>
#include <rak/functional_fun.h>
#include <torrent/download.h>
#include <torrent/exceptions.h>

Expand Down Expand Up @@ -175,7 +172,7 @@ View::initialize(const std::string& name) {
m_name = name;

// Urgh, wrong. No filtering being done.
std::for_each(dlist->begin(), dlist->end(), rak::bind1st(std::mem_fun(&View::push_back), this));
std::for_each(dlist->begin(), dlist->end(), [&](Download* d) { push_back(d); });

m_size = base_type::size();
m_focus = 0;
Expand Down
7 changes: 3 additions & 4 deletions rtorrent/src/core/view_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "config.h"

#include <algorithm>
#include <rak/functional.h>
#include <torrent/exceptions.h>
#include <torrent/object.h>

Expand All @@ -55,7 +54,7 @@ namespace core {

void
ViewManager::clear() {
std::for_each(begin(), end(), rak::call_delete<View>());
std::for_each(begin(), end(), [](View* v) { delete v; });

base_type::clear();
}
Expand All @@ -76,12 +75,12 @@ ViewManager::insert(const std::string& name) {

ViewManager::iterator
ViewManager::find(const std::string& name) {
return std::find_if(begin(), end(), rak::equal(name, std::mem_fn(&View::name)));
return std::find_if(begin(), end(), [name](View* v){ return name == v->name(); });
}

ViewManager::iterator
ViewManager::find_throw(const std::string& name) {
iterator itr = std::find_if(begin(), end(), rak::equal(name, std::mem_fn(&View::name)));
iterator itr = std::find_if(begin(), end(), [name](View* v){ return name == v->name(); });

if (itr == end())
throw torrent::input_error("Could not find view: " + name);
Expand Down
3 changes: 1 addition & 2 deletions rtorrent/src/display/text_element_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "config.h"

#include <algorithm>
#include <rak/functional.h>
#include <torrent/exceptions.h>

#include "text_element_list.h"
Expand All @@ -46,7 +45,7 @@ namespace display {

void
TextElementList::clear() {
std::for_each(begin(), end(), rak::call_delete<TextElement>());
std::for_each(begin(), end(), [](TextElement* t) { delete t; });
base_type::clear();
}

Expand Down
2 changes: 1 addition & 1 deletion rtorrent/src/input/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Manager::pressed(int key) {
if (m_textInput != NULL)
m_textInput->pressed(key);
else
std::find_if(rbegin(), rend(), std::bind2nd(std::mem_fun(&Bindings::pressed), key));
std::find_if(rbegin(), rend(), std::bind(&Bindings::pressed, std::placeholders::_1, key));
}

}
9 changes: 7 additions & 2 deletions rtorrent/src/input/path_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,13 @@ PathInput::range_type
PathInput::find_incomplete(utils::Directory& d, const std::string& f) {
range_type r;

r.first = std::find_if(d.begin(), d.end(), rak::bind2nd(std::ptr_fun(&find_complete_not_compare), f));
r.second = std::find_if(r.first, d.end(), rak::bind2nd(std::ptr_fun(&find_complete_compare), f));
r.first = std::find_if(d.begin(), d.end(), [f](const utils::directory_entry& de) {
return find_complete_not_compare(de, f);
});

r.second = std::find_if(r.first, d.end(), [f](const utils::directory_entry& de) {
return find_complete_compare(de, f);
});

return r;
}
Expand Down
5 changes: 2 additions & 3 deletions rtorrent/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#include <torrent/poll.h>
#include <torrent/data/chunk_utils.h>
#include <torrent/utils/log.h>
#include <rak/functional.h>
#include <rak/error_number.h>

#ifdef USE_EXECINFO
Expand Down Expand Up @@ -135,7 +134,7 @@ load_session_torrents() {
f->set_session(true);
f->set_init_load(true);
f->set_immediate(true);
f->slot_finished(std::bind(&rak::call_delete_func<core::DownloadFactory>, f));
f->slot_finished([f](){ delete f; });
f->load(entries.path() + first->s_name);
f->commit();
}
Expand All @@ -156,7 +155,7 @@ load_arg_torrents(char** first, char** last) {
// Replace with session torrent flag.
f->set_start(true);
f->set_init_load(true);
f->slot_finished(std::bind(&rak::call_delete_func<core::DownloadFactory>, f));
f->slot_finished([f](){ delete f; });
f->load(*first);
f->commit();
}
Expand Down
7 changes: 3 additions & 4 deletions rtorrent/src/rpc/command_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <algorithm>
#include <cstdlib>
#include <time.h>
#include <rak/functional.h>
#include <rak/string_manip.h>
#include <torrent/exceptions.h>

Expand All @@ -50,12 +49,12 @@
namespace rpc {

CommandScheduler::~CommandScheduler() {
std::for_each(begin(), end(), rak::call_delete<CommandSchedulerItem>());
std::for_each(begin(), end(), [](CommandSchedulerItem* item) { delete item; });
}

CommandScheduler::iterator
CommandScheduler::find(const std::string& key) {
return std::find_if(begin(), end(), rak::equal(key, std::mem_fun(&CommandSchedulerItem::key)));
return std::find_if(begin(), end(), [key](CommandSchedulerItem* item) { return key == item->key(); });
}

CommandScheduler::iterator
Expand Down Expand Up @@ -100,7 +99,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());
}

Expand Down
6 changes: 3 additions & 3 deletions rtorrent/src/rpc/command_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <vector>
#include <string>
#include <inttypes.h>
#include <rak/functional_fun.h>
#include <functional>

namespace torrent {
class Object;
Expand All @@ -52,7 +52,7 @@ class CommandSchedulerItem;

class CommandScheduler : public std::vector<CommandSchedulerItem*> {
public:
typedef rak::function1<void, const std::string&> SlotString;
typedef std::function<void(const std::string&)> SlotString;
typedef std::pair<int, int> Time;
typedef std::vector<CommandSchedulerItem*> base_type;

Expand All @@ -63,7 +63,7 @@ class CommandScheduler : public std::vector<CommandSchedulerItem*> {
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.

Expand Down
5 changes: 2 additions & 3 deletions rtorrent/src/rpc/scgi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ SCgi::event_read() {
utils::SocketFd fd;

while ((fd = get_fd().accept(&sa)).is_valid()) {
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fun_ref(&SCgiTask::is_available));
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fn(&SCgiTask::is_available));

if (task == m_task + max_tasks) {
// Ergh... just closing for now.
Expand All @@ -166,8 +166,7 @@ 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));
slot_write slotWrite = std::bind(&SCgiTask::receive_write, task, std::placeholders::_1, std::placeholders::_2);

torrent::thread_base::acquire_global_lock();
torrent::main_thread()->interrupt();
Expand Down
3 changes: 1 addition & 2 deletions rtorrent/src/rpc/scgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#define RTORRENT_RPC_SCGI_H

#include <string>
#include <rak/functional_fun.h>
#include <torrent/event.h>

#include "scgi_task.h"
Expand All @@ -51,7 +50,7 @@ namespace rpc {

class lt_cacheline_aligned SCgi : public torrent::Event {
public:
typedef rak::function2<bool, const char*, uint32_t> slot_write;
typedef std::function<bool(const char*, uint32_t)> slot_write;

static const int max_tasks = 100;

Expand Down
Loading

0 comments on commit 883de91

Please sign in to comment.