some general C++ 11 cleanup. some typedefs and for loops (#709)

This commit is contained in:
Arvid Norberg 2016-05-07 18:46:42 -04:00
parent 8922990fc7
commit 29902be3a0
12 changed files with 75 additions and 112 deletions

View File

@ -62,16 +62,16 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
#if defined TORRENT_BUILD_SIMULATOR
typedef sim::asio::ip::address address;
typedef sim::asio::ip::address_v4 address_v4;
using address = typedef sim::asio::ip::address;
using address_v4 = sim::asio::ip::address_v4;
#if TORRENT_USE_IPV6
typedef sim::asio::ip::address_v6 address_v6;
using address_v6 = sim::asio::ip::address_v6;
#endif
#else
typedef boost::asio::ip::address address;
typedef boost::asio::ip::address_v4 address_v4;
using address = boost::asio::ip::address;
using address_v4 = boost::asio::ip::address_v4;
#if TORRENT_USE_IPV6
typedef boost::asio::ip::address_v6 address_v6;
using address_v6 = boost::asio::ip::address_v6;
#endif
#endif // SIMULATOR
}

View File

@ -183,8 +183,7 @@ namespace libtorrent {
aux::stack_allocator m_allocations[2];
#ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::list<boost::shared_ptr<plugin> > ses_extension_list_t;
ses_extension_list_t m_ses_extensions;
std::list<boost::shared_ptr<plugin> > m_ses_extensions;
#endif
};
}

View File

@ -1164,8 +1164,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS
// this is a list to allow extensions to potentially remove themselves.
typedef std::list<boost::shared_ptr<plugin> > ses_extension_list_t;
ses_extension_list_t m_ses_extensions;
std::vector<boost::shared_ptr<plugin> > m_ses_extensions;
// the union of all session extensions' implemented_features(). This is
// used to exclude callbacks to the session extensions.

View File

@ -83,9 +83,9 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
#ifdef TORRENT_WINDOWS
typedef HANDLE handle_type;
using handle_type = HANDLE;
#else
typedef int handle_type;
using handle_type = int;
#endif
struct file_status
@ -227,7 +227,7 @@ namespace libtorrent
void TORRENT_EXTRA_EXPORT print_open_files(char const* event, char const* name);
#else
typedef boost::shared_ptr<file> file_handle;
using file_handle = boost::shared_ptr<file>;
#endif
struct TORRENT_EXTRA_EXPORT file: boost::noncopyable
@ -293,15 +293,13 @@ namespace libtorrent
size_t iov_len;
};
#else
typedef iovec iovec_t;
using iovec_t = iovec;
#endif
// use a typedef for the type of iovec_t::iov_base
// since it may differ
#ifdef TORRENT_SOLARIS
typedef char* iovec_base_t;
using iovec_base_t = char*;
#else
typedef void* iovec_base_t;
using iovec_base_t = void*;
#endif
file();

View File

@ -169,13 +169,13 @@ namespace libtorrent
int num_peers() const { return int(m_peers.size()); }
#ifdef TORRENT_OPTIMIZE_MEMORY_USAGE
typedef std::vector<torrent_peer*> peers_t;
using peers_t = std::vector<torrent_peer*>;
#else
typedef std::deque<torrent_peer*> peers_t;
using peers_t = std::deque<torrent_peer*>;
#endif
typedef peers_t::iterator iterator;
typedef peers_t::const_iterator const_iterator;
using iterator = peers_t::iterator;
using const_iterator = peers_t::const_iterator;
iterator begin_peer() { return m_peers.begin(); }
iterator end_peer() { return m_peers.end(); }
const_iterator begin_peer() const { return m_peers.begin(); }

View File

@ -68,11 +68,8 @@ namespace libtorrent
}
else if (a.is_v6())
{
typedef address_v6::bytes_type bytes_t;
bytes_t bytes = a.to_v6().to_bytes();
for (bytes_t::iterator i = bytes.begin()
, end(bytes.end()); i != end; ++i)
write_uint8(*i, out);
for (auto b : a.to_v6().to_bytes())
write_uint8(b, out);
}
#endif
}
@ -88,11 +85,9 @@ namespace libtorrent
template<class InIt>
address read_v6_address(InIt& in)
{
typedef address_v6::bytes_type bytes_t;
bytes_t bytes;
for (bytes_t::iterator i = bytes.begin()
, end(bytes.end()); i != end; ++i)
*i = read_uint8(in);
address_v6::bytes_type bytes;
for (auto& b : bytes)
b = read_uint8(in);
return address_v6(bytes);
}
#endif

View File

@ -184,11 +184,11 @@ namespace libtorrent
struct TORRENT_EXTRA_EXPORT socket_type
{
typedef tcp::socket::endpoint_type endpoint_type;
typedef tcp::socket::protocol_type protocol_type;
using endpoint_type = tcp::socket::endpoint_type;
using protocol_type = tcp::socket::protocol_type;
typedef tcp::socket::receive_buffer_size receive_buffer_size;
typedef tcp::socket::send_buffer_size send_buffer_size;
using receive_buffer_size = tcp::socket::receive_buffer_size;
using send_buffer_size = tcp::socket::send_buffer_size;
explicit socket_type(io_service& ios): m_io_service(ios), m_type(0) {}
~socket_type();

View File

@ -642,8 +642,8 @@ namespace libtorrent
int num_seeds() const;
int num_downloaders() const;
typedef std::vector<peer_connection*>::iterator peer_iterator;
typedef std::vector<peer_connection*>::const_iterator const_peer_iterator;
using peer_iterator = std::vector<peer_connection*>::iterator;
using const_peer_iterator = std::vector<peer_connection*>::const_iterator;
const_peer_iterator begin() const { return m_connections.begin(); }
const_peer_iterator end() const { return m_connections.end(); }
@ -1204,8 +1204,7 @@ namespace libtorrent
std::list<web_seed_t> m_web_seeds;
#ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::list<boost::shared_ptr<torrent_plugin> > extension_list_t;
extension_list_t m_extensions;
std::list<boost::shared_ptr<torrent_plugin> > m_extensions;
#endif
// used for tracker announces

View File

@ -86,11 +86,8 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
{
(*i)->on_alert(a);
}
for (auto& e : m_ses_extensions)
e->on_alert(a);
#else
TORRENT_UNUSED(a);
#endif

View File

@ -194,9 +194,8 @@ namespace libtorrent
void peer_list::clear_peer_prio()
{
for (peers_t::iterator i = m_peers.begin()
, end(m_peers.end()); i != end; ++i)
(*i)->peer_rank = 0;
for (auto& p : m_peers)
p->peer_rank = 0;
}
// disconnects and removes all peers that are now filtered
@ -862,12 +861,7 @@ namespace libtorrent
{
TORRENT_ASSERT(is_single_thread());
// find p in m_peers
for (const_iterator i = m_peers.begin()
, end(m_peers.end()); i != end; ++i)
{
if (*i == p) return true;
}
return false;
return std::find(m_peers.begin(), m_peers.end(), p) != m_peers.end();
}
void peer_list::set_seed(torrent_peer* p, bool s)
@ -1262,10 +1256,9 @@ namespace libtorrent
m_finished = state->is_finished;
m_max_failcount = state->max_failcount;
for (const_iterator i = m_peers.begin();
i != m_peers.end(); ++i)
for (auto const& p : m_peers)
{
m_num_connect_candidates += is_connect_candidate(**i);
m_num_connect_candidates += is_connect_candidate(*p);
}
#if TORRENT_USE_INVARIANT_CHECKS

View File

@ -632,11 +632,10 @@ namespace aux {
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::const_iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
for (auto& ext : m_ses_extensions)
{
TORRENT_TRY {
(*i)->save_state(*eptr);
ext->save_state(*eptr);
} TORRENT_CATCH(std::exception&) {}
}
#endif
@ -780,11 +779,10 @@ namespace aux {
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
for (auto& ext : m_ses_extensions)
{
TORRENT_TRY {
(*i)->load_state(*e);
ext->load_state(*e);
} TORRENT_CATCH(std::exception&) {}
}
#endif
@ -3147,11 +3145,10 @@ namespace aux {
#ifndef TORRENT_DISABLE_EXTENSIONS
if (m_session_extension_features & plugin::tick_feature)
{
for (ses_extension_list_t::const_iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
for (auto& ext : m_ses_extensions)
{
TORRENT_TRY {
(*i)->on_tick();
ext->on_tick();
} TORRENT_CATCH(std::exception&) {}
}
}
@ -3871,10 +3868,9 @@ namespace aux {
{
peers.push_back(peer_connection_handle(static_cast<peer_connection*>((*i)->connection)->self()));
}
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
for (auto& e : m_ses_extensions)
{
if ((*i)->on_optimistic_unchoke(peers))
if (e->on_optimistic_unchoke(peers))
break;
}
// then convert back to the internal torrent_peer pointers
@ -4263,11 +4259,10 @@ namespace aux {
, peer_connection* pc)
{
#ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
for (auto& e : m_ses_extensions)
{
add_torrent_params p;
if ((*i)->on_unknown_torrent(info_hash, peer_connection_handle(pc->self()), p))
if (e->on_unknown_torrent(info_hash, peer_connection_handle(pc->self()), p))
{
error_code ec;
torrent_handle handle = add_torrent(p, ec);
@ -4663,10 +4658,10 @@ namespace aux {
void session_impl::add_extensions_to_torrent(
boost::shared_ptr<torrent> const& torrent_ptr, void* userdata)
{
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i)
for (auto& e : m_ses_extensions)
{
boost::shared_ptr<torrent_plugin> tp((*i)->new_torrent(torrent_ptr->get_handle(), userdata));
boost::shared_ptr<torrent_plugin> tp(e->new_torrent(
torrent_ptr->get_handle(), userdata));
if (tp) torrent_ptr->add_extension(tp);
}
}

View File

@ -1428,7 +1428,7 @@ namespace libtorrent
void torrent::remove_extension(boost::shared_ptr<torrent_plugin> ext)
{
extension_list_t::iterator i = std::find(m_extensions.begin(), m_extensions.end(), ext);
auto i = std::find(m_extensions.begin(), m_extensions.end(), ext);
if (i == m_extensions.end()) return;
m_extensions.erase(i);
}
@ -2095,11 +2095,10 @@ namespace libtorrent
// call on_unload() on extensions
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->on_unload();
ext->on_unload();
} TORRENT_CATCH (std::exception&) {}
}
@ -4060,11 +4059,10 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->on_piece_pass(index);
ext->on_piece_pass(index);
} TORRENT_CATCH (std::exception&) {}
}
#endif
@ -4264,11 +4262,10 @@ namespace libtorrent
add_failed_bytes(m_torrent_file->piece_size(index));
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->on_piece_failed(index);
ext->on_piece_failed(index);
} TORRENT_CATCH (std::exception&) {}
}
#endif
@ -6391,11 +6388,10 @@ namespace libtorrent
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
boost::shared_ptr<peer_plugin>
pp((*i)->new_connection(peer_connection_handle(c.get()->self())));
pp(ext->new_connection(peer_connection_handle(c.get()->self())));
if (pp) c->add_extension(pp);
}
#endif
@ -7097,11 +7093,10 @@ namespace libtorrent
peerinfo->prev_amount_upload = 0;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
boost::shared_ptr<peer_plugin> pp((*i)->new_connection(
boost::shared_ptr<peer_plugin> pp(ext->new_connection(
peer_connection_handle(c.get()->self())));
if (pp) c->add_extension(pp);
} TORRENT_CATCH (std::exception&) {}
@ -7394,10 +7389,9 @@ namespace libtorrent
TORRENT_TRY
{
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
boost::shared_ptr<peer_plugin> pp((*i)->new_connection(
boost::shared_ptr<peer_plugin> pp(ext->new_connection(
peer_connection_handle(p->self())));
if (pp) p->add_extension(pp);
}
@ -8034,11 +8028,10 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->on_files_checked();
ext->on_files_checked();
} TORRENT_CATCH (std::exception&) {}
}
#endif
@ -9024,11 +9017,10 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
if ((*i)->on_pause()) return;
if (ext->on_pause()) return;
} TORRENT_CATCH (std::exception&) {}
}
#endif
@ -9260,11 +9252,10 @@ namespace libtorrent
if (is_paused()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
if ((*i)->on_resume()) return;
if (ext->on_resume()) return;
} TORRENT_CATCH (std::exception&) {}
}
#endif
@ -9492,11 +9483,10 @@ namespace libtorrent
boost::weak_ptr<torrent> self(shared_from_this());
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->tick();
ext->tick();
} TORRENT_CATCH (std::exception&) {}
}
@ -11070,11 +11060,10 @@ namespace libtorrent
state_updated();
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->on_state(m_state);
ext->on_state(m_state);
} TORRENT_CATCH (std::exception&) {}
}
#endif
@ -11084,11 +11073,10 @@ namespace libtorrent
void torrent::notify_extension_add_peer(tcp::endpoint const& ip
, int src, int flags)
{
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
for (auto& ext : m_extensions)
{
TORRENT_TRY {
(*i)->on_add_peer(ip, src, flags);
ext->on_add_peer(ip, src, flags);
} TORRENT_CATCH (std::exception&) {}
}
}