Skip to content

Commit

Permalink
cleanup: Remove rak/functional.h
Browse files Browse the repository at this point in the history
This commit replaces the `rak/functional.h` features with lambdas and std functions.

There was one instance with `std::sort` where the comparison operator was always evaluating to false and it wasn't sorting anything. This is removed in favour of the default comparison operator.

`std::sort(transferChunks.begin(), transferChunks.end());`
  • Loading branch information
stickz committed Jan 12, 2025
1 parent 2b73c92 commit 712e7e5
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 536 deletions.
501 changes: 0 additions & 501 deletions rak/functional.h

This file was deleted.

1 change: 0 additions & 1 deletion src/command_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <regex>

#include <rak/algorithm.h>
#include <rak/functional.h>
#include <torrent/utils/log.h>

#include "core/manager.h"
Expand Down
1 change: 0 additions & 1 deletion src/core/curl_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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
1 change: 0 additions & 1 deletion 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
5 changes: 2 additions & 3 deletions 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 @@ -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_fun(&Download::info), std::mem_fun(&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_fun(&Download::info), std::mem_fun(&torrent::DownloadInfo::hash))));
return std::find_if(begin(), end(), [key](Download* d) { return key == d->info()->hash(); });
}

Download*
Expand Down
1 change: 0 additions & 1 deletion 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
3 changes: 1 addition & 2 deletions src/core/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

Expand Down Expand Up @@ -144,7 +143,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
5 changes: 2 additions & 3 deletions 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 Down Expand Up @@ -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_fun(&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_fun(&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
1 change: 0 additions & 1 deletion src/display/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <stdexcept>
#include <algorithm>
#include <rak/functional.h>

#include "canvas.h"
#include "globals.h"
Expand Down
3 changes: 1 addition & 2 deletions src/display/window_download_chunks_seen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <cmath>
#include <stdexcept>
#include <rak/functional.h>
#include <rak/string_manip.h>
#include <torrent/bitfield.h>
#include <torrent/data/block.h>
Expand Down Expand Up @@ -95,7 +94,7 @@ WindowDownloadChunksSeen::redraw() {
std::vector<torrent::BlockList*> transferChunks(transfers->size(), 0);

std::copy(transfers->begin(), transfers->end(), transferChunks.begin());
std::sort(transferChunks.begin(), transferChunks.end(), rak::less2(std::mem_fun(&torrent::BlockList::index), std::mem_fun(&torrent::BlockList::index)));
std::sort(transferChunks.begin(), transferChunks.end());

std::vector<torrent::BlockList*>::const_iterator itrTransfer = transferChunks.begin();

Expand Down
3 changes: 1 addition & 2 deletions src/display/window_http_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "core/http_queue.h"

#include "canvas.h"
#include "rak/functional.h"
#include "window_http_queue.h"

namespace display {
Expand Down Expand Up @@ -145,7 +144,7 @@ WindowHttpQueue::receive_insert(core::CurlGet* h) {

void
WindowHttpQueue::receive_erase(core::CurlGet* h) {
Container::iterator itr = std::find_if(m_container.begin(), m_container.end(), rak::equal(h, std::mem_fun_ref(&Node::get_http)));
Container::iterator itr = std::find_if(m_container.begin(), m_container.end(), [h](Node n) { return h == n.get_http(); });

if (itr == m_container.end())
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
Expand Down
11 changes: 7 additions & 4 deletions src/input/path_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <functional>
#include <rak/algorithm.h>
#include <rak/functional.h>
#include <rak/path.h>

#include <dirent.h>
Expand Down Expand Up @@ -105,7 +104,7 @@ PathInput::receive_do_complete() {
if (r.first == r.second)
return; // Show some nice colors here.

std::string base = rak::make_base<std::string>(r.first, r.second, rak::const_mem_ref(&utils::directory_entry::s_name));
std::string base = rak::make_base<std::string>(r.first, r.second, std::mem_fn(&utils::directory_entry::s_name));

// Clear the path after the cursor to make this code cleaner. It's
// not really nessesary to add the complexity just because someone
Expand Down Expand Up @@ -154,8 +153,12 @@ 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
3 changes: 1 addition & 2 deletions 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 @@ -55,7 +54,7 @@ CommandScheduler::~CommandScheduler() {

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
9 changes: 3 additions & 6 deletions src/rpc/object_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include "object_storage.h"

#include "rak/functional.h"
#include "parse.h"
#include "parse_commands.h"

Expand Down Expand Up @@ -223,8 +222,7 @@ object_storage::erase_multi_key(const torrent::raw_string& key, const std::strin
if (r_itr == m_rlookup.end())
return;

rlookup_mapped_iterator rm_itr = std::find_if(r_itr->second.begin(), r_itr->second.end(),
rak::equal(key, rak::mem_ptr(&value_type::first)));
rlookup_mapped_iterator rm_itr = std::find_if(r_itr->second.begin(), r_itr->second.end(), [key](value_type* type) { return key == type->first; });

if (rm_itr != r_itr->second.end())
r_itr->second.erase(rm_itr);
Expand All @@ -243,8 +241,7 @@ object_storage::set_multi_key_obj(const torrent::raw_string& key, const std::str
if (r_itr == m_rlookup.end())
r_itr = m_rlookup.insert(std::make_pair(cmd_key, rlookup_type::mapped_type())).first;

if (std::find_if(r_itr->second.begin(), r_itr->second.end(),
rak::equal(key, rak::mem_ptr(&value_type::first))) == r_itr->second.end())
if (std::find_if(r_itr->second.begin(), r_itr->second.end(), [key](value_type* type) { return key == type->first; }) == r_itr->second.end())
r_itr->second.push_back(&*itr);
}

Expand All @@ -259,7 +256,7 @@ object_storage::rlookup_list(const std::string& cmd_key) {

if (r_itr != m_rlookup.end())
std::transform(r_itr->second.begin(), r_itr->second.end(), std::back_inserter(result),
std::bind(&key_type::c_str, std::bind(rak::mem_ptr(&value_type::first), std::placeholders::_1)));
std::bind(&key_type::c_str, std::bind(std::mem_fn(&value_type::first), std::placeholders::_1)));

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/parse_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <algorithm>
#include <fstream>
#include <string>
#include <rak/functional.h>
#include <functional>
#include <rak/path.h>
#include <torrent/exceptions.h>

Expand Down
7 changes: 2 additions & 5 deletions src/ui/element_peer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

#include "config.h"

#include <rak/functional.h>

#include <torrent/exceptions.h>
#include <torrent/rate.h>
#include <torrent/hash_string.h>
Expand All @@ -63,11 +61,10 @@ ElementPeerList::ElementPeerList(core::Download* d) :

m_listItr = m_list.end();

std::for_each(m_download->download()->connection_list()->begin(), m_download->download()->connection_list()->end(),
rak::bind1st(std::mem_fun<void,PList,PList::const_reference>(&PList::push_back), &m_list));

torrent::ConnectionList* connection_list = m_download->download()->connection_list();

std::for_each(connection_list->begin(), connection_list->end(), [&](torrent::Peer* peer) { m_list.push_back(peer); });

m_peer_connected = connection_list->signal_connected().insert(connection_list->signal_connected().end(),
std::bind(&ElementPeerList::receive_peer_connected, this, std::placeholders::_1));
m_peer_disconnected = connection_list->signal_disconnected().insert(connection_list->signal_disconnected().end(),
Expand Down

0 comments on commit 712e7e5

Please sign in to comment.