Skip to content

Commit

Permalink
First set of changes for c++11 migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed May 8, 2014
1 parent 3483cb8 commit 77a0f35
Show file tree
Hide file tree
Showing 76 changed files with 336 additions and 323 deletions.
4 changes: 2 additions & 2 deletions rak/priority_queue_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#ifndef RAK_PRIORITY_QUEUE_DEFAULT_H
#define RAK_PRIORITY_QUEUE_DEFAULT_H

#include <tr1/functional>
#include lt_tr1_functional
#include <rak/allocators.h>
#include <rak/priority_queue.h>
#include <rak/timer.h>
Expand All @@ -48,7 +48,7 @@ namespace rak {

class priority_item {
public:
typedef std::tr1::function<void (void)> slot_void;
typedef std::function<void (void)> slot_void;

priority_item() {}
~priority_item() {
Expand Down
14 changes: 11 additions & 3 deletions scripts/checks.m4
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,11 @@ AC_DEFUN([TORRENT_CHECK_TR1_LIB], [
], [
AC_MSG_RESULT(no)
AC_DEFINE(USE_TR1_LIB, 0, Define to 1 if you need to use TR1 containers.)
AC_DEFINE(lt_tr1_, "", [Prefix to use for headers first included with TR1.])
AC_DEFINE([lt_tr1_array], [<array>], [TR1 array])
AC_DEFINE([lt_tr1_functional], [<functional>], [TR1 functional])
AC_DEFINE([lt_tr1_memory], [<memory>], [TR1 memory])
], [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <tr1/unordered_map>
Expand All @@ -428,14 +432,18 @@ AC_DEFUN([TORRENT_CHECK_TR1_LIB], [
], [
AC_MSG_RESULT([yes])
AC_DEFINE(USE_TR1_LIB, 1, Define to 1 if you need to use TR1 containers.)
AC_DEFINE(lt_tr1_, "tr1/", [Prefix to use for headers first included with TR1.])
AH_BOTTOM([namespace std { namespace tr1 {} using namespace tr1; }])
], [
AC_MSG_ERROR([No support for C++11 standard library nor TR1 extensions found.])
])
])
AH_VERBATIM(lt_tr1_zzz, [
#if USE_TR1_LIB == 1
namespace std { namespace tr1 {} using namespace tr1; }
#endif
])
AC_LANG_POP(C++)
])

Expand Down
8 changes: 4 additions & 4 deletions src/data/chunk_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include <string>
#include <vector>
#include <tr1/functional>
#include lt_tr1_functional

#include "chunk.h"
#include "chunk_handle.h"
Expand All @@ -59,9 +59,9 @@ class ChunkList : private std::vector<ChunkListNode> {
typedef std::vector<ChunkListNode> base_type;
typedef std::vector<ChunkListNode*> Queue;

typedef std::tr1::function<Chunk* (uint32_t, int)> slot_chunk_index;
typedef std::tr1::function<uint64_t ()> slot_value;
typedef std::tr1::function<void (const std::string&)> slot_string;
typedef std::function<Chunk* (uint32_t, int)> slot_chunk_index;
typedef std::function<uint64_t ()> slot_value;
typedef std::function<void (const std::string&)> slot_string;

using base_type::value_type;
using base_type::reference;
Expand Down
4 changes: 2 additions & 2 deletions src/data/hash_check_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include <deque>
#include <pthread.h>
#include <tr1/functional>
#include lt_tr1_functional

#include "rak/allocators.h"

Expand All @@ -51,7 +51,7 @@ class HashChunk;
class lt_cacheline_aligned HashCheckQueue : private std::deque<HashChunk*, rak::cacheline_allocator<HashChunk*> > {
public:
typedef std::deque<HashChunk*, rak::cacheline_allocator<HashChunk*> > base_type;
typedef std::tr1::function<void (HashChunk*, const HashString&)> slot_chunk_handle;
typedef std::function<void (HashChunk*, const HashString&)> slot_chunk_handle;

using base_type::iterator;

Expand Down
8 changes: 4 additions & 4 deletions src/data/hash_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#define LT_LOG_DATA(data, log_level, log_fmt, ...) \
lt_log_print_data(LOG_STORAGE_##log_level, data, "hash_queue", log_fmt, __VA_ARGS__);

namespace tr1 { using namespace std::tr1; }
namespace tr1 { using namespace std; }

namespace torrent {

Expand Down Expand Up @@ -87,7 +87,7 @@ HashQueue::HashQueue(thread_disk* thread) :
m_thread_disk(thread) {

pthread_mutex_init(&m_done_chunks_lock, NULL);
m_thread_disk->hash_queue()->slot_chunk_done() = tr1::bind(&HashQueue::chunk_done, this, tr1::placeholders::_1, tr1::placeholders::_2);
m_thread_disk->hash_queue()->slot_chunk_done() = std::bind(&HashQueue::chunk_done, this, std::placeholders::_1, std::placeholders::_2);
}


Expand Down Expand Up @@ -176,9 +176,9 @@ HashQueue::work() {
// TODO: This is not optimal as we jump around... Check for front
// of HashQueue in done_chunks instead.

iterator itr = std::find_if(begin(), end(), tr1::bind(std::equal_to<HashChunk*>(),
iterator itr = std::find_if(begin(), end(), std::bind(std::equal_to<HashChunk*>(),
hash_chunk,
tr1::bind(&HashQueueNode::get_chunk, tr1::placeholders::_1)));
std::bind(&HashQueueNode::get_chunk, std::placeholders::_1)));

// TODO: Fix this...
if (itr == end())
Expand Down
4 changes: 2 additions & 2 deletions src/data/hash_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <deque>
#include <map>
#include <pthread.h>
#include <tr1/functional>
#include lt_tr1_functional

#include "torrent/hash_string.h"
#include "hash_queue_node.h"
Expand All @@ -63,7 +63,7 @@ class lt_cacheline_aligned HashQueue : private std::deque<HashQueueNode> {
typedef std::map<HashChunk*, torrent::HashString> done_chunks_type;

typedef HashQueueNode::slot_done_type slot_done_type;
typedef std::tr1::function<void (bool)> slot_bool;
typedef std::function<void (bool)> slot_bool;

using base_type::iterator;

Expand Down
4 changes: 2 additions & 2 deletions src/data/hash_queue_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define LIBTORRENT_DATA_HASH_QUEUE_NODE_H

#include <string>
#include <tr1/functional>
#include lt_tr1_functional
#include <inttypes.h>

#include "chunk_handle.h"
Expand All @@ -50,7 +50,7 @@ class download_data;

class HashQueueNode {
public:
typedef std::tr1::function<void (ChunkHandle, const char*)> slot_done_type;
typedef std::function<void (ChunkHandle, const char*)> slot_done_type;
typedef download_data* id_type;

HashQueueNode(id_type id, HashChunk* c, slot_done_type d) :
Expand Down
4 changes: 2 additions & 2 deletions src/data/hash_torrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include <string>
#include <inttypes.h>
#include <tr1/functional>
#include lt_tr1_functional
#include <rak/priority_queue_default.h>

#include "data/chunk_handle.h"
Expand All @@ -53,7 +53,7 @@ class HashTorrent {
public:
typedef ranges<uint32_t> Ranges;

typedef std::tr1::function<void (ChunkHandle)> slot_chunk_handle;
typedef std::function<void (ChunkHandle)> slot_chunk_handle;

HashTorrent(ChunkList* c);
~HashTorrent() { clear(); }
Expand Down
10 changes: 5 additions & 5 deletions src/dht/dht_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "config.h"

#if HAVE_TR1
#include <tr1/unordered_map>
#include <lt_tr1_unordered_map>
#else
#include <map>
#endif
Expand Down Expand Up @@ -104,9 +104,9 @@ struct hashstring_ptr_equal : public std::binary_function<const HashString*, con
{ return *one == *two; }
};

class DhtNodeList : public std::tr1::unordered_map<const HashString*, DhtNode*, hashstring_ptr_hash, hashstring_ptr_equal> {
class DhtNodeList : public std::unordered_map<const HashString*, DhtNode*, hashstring_ptr_hash, hashstring_ptr_equal> {
public:
typedef std::tr1::unordered_map<const HashString*, DhtNode*, hashstring_ptr_hash, hashstring_ptr_equal> base_type;
typedef std::unordered_map<const HashString*, DhtNode*, hashstring_ptr_hash, hashstring_ptr_equal> base_type;

// Define accessor iterator with more convenient access to the key and
// element values. Allows changing the map definition more easily if needed.
Expand All @@ -125,9 +125,9 @@ class DhtNodeList : public std::tr1::unordered_map<const HashString*, DhtNode*,

};

class DhtTrackerList : public std::tr1::unordered_map<HashString, DhtTracker*, hashstring_hash> {
class DhtTrackerList : public std::unordered_map<HashString, DhtTracker*, hashstring_hash> {
public:
typedef std::tr1::unordered_map<HashString, DhtTracker*, hashstring_hash> base_type;
typedef std::unordered_map<HashString, DhtTracker*, hashstring_hash> base_type;

template<typename T>
struct accessor_wrapper : public T {
Expand Down
4 changes: 2 additions & 2 deletions src/dht/dht_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ DhtRouter::start(int port) {
m_server.start(port);

// Set timeout slot and schedule it to be called immediately for initial bootstrapping if necessary.
m_taskTimeout.slot() = std::tr1::bind(&DhtRouter::receive_timeout_bootstrap, this);
m_taskTimeout.slot() = std::bind(&DhtRouter::receive_timeout_bootstrap, this);
priority_queue_insert(&taskScheduler, &m_taskTimeout, (cachedTime + rak::timer::from_seconds(1)).round_seconds());
}

Expand Down Expand Up @@ -416,7 +416,7 @@ DhtRouter::receive_timeout_bootstrap() {
delete m_contacts;
m_contacts = NULL;

m_taskTimeout.slot() = std::tr1::bind(&DhtRouter::receive_timeout, this);
m_taskTimeout.slot() = std::bind(&DhtRouter::receive_timeout, this);

if (!m_numRefresh) {
// If we're still in the startup, do the usual refreshing too.
Expand Down
4 changes: 2 additions & 2 deletions src/dht/dht_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ DhtServer::start(int port) {
throw;
}

m_taskTimeout.slot() = std::tr1::bind(&DhtServer::receive_timeout, this);
m_taskTimeout.slot() = std::bind(&DhtServer::receive_timeout, this);

m_uploadNode.set_list_iterator(m_uploadThrottle->end());
m_uploadNode.slot_activate() = std::tr1::bind(&SocketBase::receive_throttle_up_activate, static_cast<SocketBase*>(this));
m_uploadNode.slot_activate() = std::bind(&SocketBase::receive_throttle_up_activate, static_cast<SocketBase*>(this));

m_downloadNode.set_list_iterator(m_downloadThrottle->end());
m_downloadThrottle->insert(&m_downloadNode);
Expand Down
6 changes: 3 additions & 3 deletions src/download/delegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include <string>
#include <vector>
#include <tr1/functional>
#include lt_tr1_functional

#include "torrent/data/transfer_list.h"

Expand All @@ -54,8 +54,8 @@ class PeerInfo;

class Delegator {
public:
typedef std::tr1::function<uint32_t (PeerChunks*, bool)> slot_peer_chunk;
typedef std::tr1::function<uint32_t (uint32_t)> slot_size;
typedef std::function<uint32_t (PeerChunks*, bool)> slot_peer_chunk;
typedef std::function<uint32_t (uint32_t)> slot_size;

static const unsigned int block_size = 1 << 14;

Expand Down
32 changes: 16 additions & 16 deletions src/download/download_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#define LT_LOG_THIS(log_level, log_fmt, ...) \
lt_log_print_info(LOG_TORRENT_##log_level, m_ptr->info(), "download", log_fmt, __VA_ARGS__);

namespace tr1 { using namespace std::tr1; }
namespace tr1 { using namespace std; }

namespace torrent {

Expand Down Expand Up @@ -107,28 +107,28 @@ DownloadMain::DownloadMain() :
m_tracker_list = new TrackerList();
m_tracker_controller = new TrackerController(m_tracker_list);

m_tracker_list->slot_success() = tr1::bind(&TrackerController::receive_success, m_tracker_controller, tr1::placeholders::_1, tr1::placeholders::_2);
m_tracker_list->slot_failure() = tr1::bind(&TrackerController::receive_failure, m_tracker_controller, tr1::placeholders::_1, tr1::placeholders::_2);
m_tracker_list->slot_scrape_success() = tr1::bind(&TrackerController::receive_scrape, m_tracker_controller, tr1::placeholders::_1);
m_tracker_list->slot_tracker_enabled() = tr1::bind(&TrackerController::receive_tracker_enabled, m_tracker_controller, tr1::placeholders::_1);
m_tracker_list->slot_tracker_disabled() = tr1::bind(&TrackerController::receive_tracker_disabled, m_tracker_controller, tr1::placeholders::_1);
m_tracker_list->slot_success() = std::bind(&TrackerController::receive_success, m_tracker_controller, std::placeholders::_1, std::placeholders::_2);
m_tracker_list->slot_failure() = std::bind(&TrackerController::receive_failure, m_tracker_controller, std::placeholders::_1, std::placeholders::_2);
m_tracker_list->slot_scrape_success() = std::bind(&TrackerController::receive_scrape, m_tracker_controller, std::placeholders::_1);
m_tracker_list->slot_tracker_enabled() = std::bind(&TrackerController::receive_tracker_enabled, m_tracker_controller, std::placeholders::_1);
m_tracker_list->slot_tracker_disabled() = std::bind(&TrackerController::receive_tracker_disabled, m_tracker_controller, std::placeholders::_1);

m_connectionList = new ConnectionList(this);

m_delegator.slot_chunk_find() = std::tr1::bind(&ChunkSelector::find, m_chunkSelector, tr1::placeholders::_1, tr1::placeholders::_2);
m_delegator.slot_chunk_size() = std::tr1::bind(&FileList::chunk_index_size, file_list(), tr1::placeholders::_1);
m_delegator.slot_chunk_find() = std::bind(&ChunkSelector::find, m_chunkSelector, std::placeholders::_1, std::placeholders::_2);
m_delegator.slot_chunk_size() = std::bind(&FileList::chunk_index_size, file_list(), std::placeholders::_1);

m_delegator.transfer_list()->slot_canceled() = std::tr1::bind(&ChunkSelector::not_using_index, m_chunkSelector, tr1::placeholders::_1);
m_delegator.transfer_list()->slot_queued() = std::tr1::bind(&ChunkSelector::using_index, m_chunkSelector, tr1::placeholders::_1);
m_delegator.transfer_list()->slot_completed() = std::tr1::bind(&DownloadMain::receive_chunk_done, this, tr1::placeholders::_1);
m_delegator.transfer_list()->slot_corrupt() = std::tr1::bind(&DownloadMain::receive_corrupt_chunk, this, tr1::placeholders::_1);
m_delegator.transfer_list()->slot_canceled() = std::bind(&ChunkSelector::not_using_index, m_chunkSelector, std::placeholders::_1);
m_delegator.transfer_list()->slot_queued() = std::bind(&ChunkSelector::using_index, m_chunkSelector, std::placeholders::_1);
m_delegator.transfer_list()->slot_completed() = std::bind(&DownloadMain::receive_chunk_done, this, std::placeholders::_1);
m_delegator.transfer_list()->slot_corrupt() = std::bind(&DownloadMain::receive_corrupt_chunk, this, std::placeholders::_1);

m_delayDisconnectPeers.slot() = std::tr1::bind(&ConnectionList::disconnect_queued, m_connectionList);
m_taskTrackerRequest.slot() = std::tr1::bind(&DownloadMain::receive_tracker_request, this);
m_delayDisconnectPeers.slot() = std::bind(&ConnectionList::disconnect_queued, m_connectionList);
m_taskTrackerRequest.slot() = std::bind(&DownloadMain::receive_tracker_request, this);

m_chunkList->set_data(file_list()->mutable_data());
m_chunkList->slot_create_chunk() = tr1::bind(&FileList::create_chunk_index, file_list(), tr1::placeholders::_1, tr1::placeholders::_2);
m_chunkList->slot_free_diskspace() = tr1::bind(&FileList::free_diskspace, file_list());
m_chunkList->slot_create_chunk() = std::bind(&FileList::create_chunk_index, file_list(), std::placeholders::_1, std::placeholders::_2);
m_chunkList->slot_free_diskspace() = std::bind(&FileList::free_diskspace, file_list());
}

DownloadMain::~DownloadMain() {
Expand Down
20 changes: 10 additions & 10 deletions src/download/download_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#define LT_LOG_STORAGE_ERRORS(log_fmt, ...) \
lt_log_print_info(LOG_PROTOCOL_STORAGE_ERRORS, this->info(), "storage_errors", log_fmt, __VA_ARGS__);

namespace tr1 { using namespace std::tr1; }
namespace tr1 { using namespace std; }

namespace torrent {

Expand All @@ -76,14 +76,14 @@ DownloadWrapper::DownloadWrapper() :
m_hashChecker(NULL),
m_connectionType(0) {

m_main->delay_download_done().slot() = std::tr1::bind(&download_data::call_download_done, data());
m_main->delay_download_done().slot() = std::bind(&download_data::call_download_done, data());

m_main->peer_list()->set_info(info());
m_main->tracker_list()->set_info(info());
m_main->tracker_controller()->slot_success() = tr1::bind(&DownloadWrapper::receive_tracker_success, this, tr1::placeholders::_1);
m_main->tracker_controller()->slot_failure() = tr1::bind(&DownloadWrapper::receive_tracker_failed, this, tr1::placeholders::_1);
m_main->tracker_controller()->slot_success() = std::bind(&DownloadWrapper::receive_tracker_success, this, std::placeholders::_1);
m_main->tracker_controller()->slot_failure() = std::bind(&DownloadWrapper::receive_tracker_failed, this, std::placeholders::_1);

m_main->chunk_list()->slot_storage_error() = tr1::bind(&DownloadWrapper::receive_storage_error, this, tr1::placeholders::_1);
m_main->chunk_list()->slot_storage_error() = std::bind(&DownloadWrapper::receive_storage_error, this, std::placeholders::_1);
}

DownloadWrapper::~DownloadWrapper() {
Expand Down Expand Up @@ -112,8 +112,8 @@ DownloadWrapper::initialize(const std::string& hash, const std::string& id) {

info()->mutable_local_id().assign(id.c_str());

info()->slot_left() = tr1::bind(&FileList::left_bytes, m_main->file_list());
info()->slot_completed() = tr1::bind(&FileList::completed_bytes, m_main->file_list());
info()->slot_left() = std::bind(&FileList::left_bytes, m_main->file_list());
info()->slot_completed() = std::bind(&FileList::completed_bytes, m_main->file_list());

file_list()->mutable_data()->mutable_hash().assign(hash.c_str());

Expand All @@ -123,8 +123,8 @@ DownloadWrapper::initialize(const std::string& hash, const std::string& id) {
m_hashChecker = new HashTorrent(m_main->chunk_list());

// Connect various signals and slots.
m_hashChecker->slot_check_chunk() = std::tr1::bind(&DownloadWrapper::check_chunk_hash, this, std::tr1::placeholders::_1);
m_hashChecker->delay_checked().slot() = std::tr1::bind(&DownloadWrapper::receive_initial_hash, this);
m_hashChecker->slot_check_chunk() = std::bind(&DownloadWrapper::check_chunk_hash, this, std::placeholders::_1);
m_hashChecker->delay_checked().slot() = std::bind(&DownloadWrapper::receive_initial_hash, this);
}

void
Expand Down Expand Up @@ -240,7 +240,7 @@ DownloadWrapper::check_chunk_hash(ChunkHandle handle) {
ChunkHandle new_handle = m_main->chunk_list()->get(handle.index(), ChunkList::get_blocking);
m_main->chunk_list()->release(&handle);

hash_queue()->push_back(new_handle, data(), tr1::bind(&DownloadWrapper::receive_hash_done, this, tr1::placeholders::_1, tr1::placeholders::_2));
hash_queue()->push_back(new_handle, data(), std::bind(&DownloadWrapper::receive_hash_done, this, std::placeholders::_1, std::placeholders::_2));
}

void
Expand Down

0 comments on commit 77a0f35

Please sign in to comment.