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 namespace libtorrent
{ {
#if defined TORRENT_BUILD_SIMULATOR #if defined TORRENT_BUILD_SIMULATOR
typedef sim::asio::ip::address address; using address = typedef sim::asio::ip::address;
typedef sim::asio::ip::address_v4 address_v4; using address_v4 = sim::asio::ip::address_v4;
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
typedef sim::asio::ip::address_v6 address_v6; using address_v6 = sim::asio::ip::address_v6;
#endif #endif
#else #else
typedef boost::asio::ip::address address; using address = boost::asio::ip::address;
typedef boost::asio::ip::address_v4 address_v4; using address_v4 = boost::asio::ip::address_v4;
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
typedef boost::asio::ip::address_v6 address_v6; using address_v6 = boost::asio::ip::address_v6;
#endif #endif
#endif // SIMULATOR #endif // SIMULATOR
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -632,11 +632,10 @@ namespace aux {
#endif #endif
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::const_iterator i = m_ses_extensions.begin() for (auto& ext : m_ses_extensions)
, end(m_ses_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->save_state(*eptr); ext->save_state(*eptr);
} TORRENT_CATCH(std::exception&) {} } TORRENT_CATCH(std::exception&) {}
} }
#endif #endif
@ -780,11 +779,10 @@ namespace aux {
#endif #endif
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::iterator i = m_ses_extensions.begin() for (auto& ext : m_ses_extensions)
, end(m_ses_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->load_state(*e); ext->load_state(*e);
} TORRENT_CATCH(std::exception&) {} } TORRENT_CATCH(std::exception&) {}
} }
#endif #endif
@ -3147,11 +3145,10 @@ namespace aux {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
if (m_session_extension_features & plugin::tick_feature) if (m_session_extension_features & plugin::tick_feature)
{ {
for (ses_extension_list_t::const_iterator i = m_ses_extensions.begin() for (auto& ext : m_ses_extensions)
, end(m_ses_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_tick(); ext->on_tick();
} TORRENT_CATCH(std::exception&) {} } TORRENT_CATCH(std::exception&) {}
} }
} }
@ -3871,10 +3868,9 @@ namespace aux {
{ {
peers.push_back(peer_connection_handle(static_cast<peer_connection*>((*i)->connection)->self())); peers.push_back(peer_connection_handle(static_cast<peer_connection*>((*i)->connection)->self()));
} }
for (ses_extension_list_t::iterator i = m_ses_extensions.begin() for (auto& e : m_ses_extensions)
, end(m_ses_extensions.end()); i != end; ++i)
{ {
if ((*i)->on_optimistic_unchoke(peers)) if (e->on_optimistic_unchoke(peers))
break; break;
} }
// then convert back to the internal torrent_peer pointers // then convert back to the internal torrent_peer pointers
@ -4263,11 +4259,10 @@ namespace aux {
, peer_connection* pc) , peer_connection* pc)
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::iterator i = m_ses_extensions.begin() for (auto& e : m_ses_extensions)
, end(m_ses_extensions.end()); i != end; ++i)
{ {
add_torrent_params p; 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; error_code ec;
torrent_handle handle = add_torrent(p, ec); torrent_handle handle = add_torrent(p, ec);
@ -4663,10 +4658,10 @@ namespace aux {
void session_impl::add_extensions_to_torrent( void session_impl::add_extensions_to_torrent(
boost::shared_ptr<torrent> const& torrent_ptr, void* userdata) boost::shared_ptr<torrent> const& torrent_ptr, void* userdata)
{ {
for (ses_extension_list_t::iterator i = m_ses_extensions.begin() for (auto& e : m_ses_extensions)
, end(m_ses_extensions.end()); i != end; ++i)
{ {
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); 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) 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; if (i == m_extensions.end()) return;
m_extensions.erase(i); m_extensions.erase(i);
} }
@ -2095,11 +2095,10 @@ namespace libtorrent
// call on_unload() on extensions // call on_unload() on extensions
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_unload(); ext->on_unload();
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
@ -4060,11 +4059,10 @@ namespace libtorrent
} }
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_piece_pass(index); ext->on_piece_pass(index);
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
#endif #endif
@ -4264,11 +4262,10 @@ namespace libtorrent
add_failed_bytes(m_torrent_file->piece_size(index)); add_failed_bytes(m_torrent_file->piece_size(index));
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_piece_failed(index); ext->on_piece_failed(index);
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
#endif #endif
@ -6391,11 +6388,10 @@ namespace libtorrent
#endif #endif
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
boost::shared_ptr<peer_plugin> 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); if (pp) c->add_extension(pp);
} }
#endif #endif
@ -7097,11 +7093,10 @@ namespace libtorrent
peerinfo->prev_amount_upload = 0; peerinfo->prev_amount_upload = 0;
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { 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()))); peer_connection_handle(c.get()->self())));
if (pp) c->add_extension(pp); if (pp) c->add_extension(pp);
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
@ -7394,10 +7389,9 @@ namespace libtorrent
TORRENT_TRY TORRENT_TRY
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
boost::shared_ptr<peer_plugin> pp((*i)->new_connection( boost::shared_ptr<peer_plugin> pp(ext->new_connection(
peer_connection_handle(p->self()))); peer_connection_handle(p->self())));
if (pp) p->add_extension(pp); if (pp) p->add_extension(pp);
} }
@ -8034,11 +8028,10 @@ namespace libtorrent
} }
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_files_checked(); ext->on_files_checked();
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
#endif #endif
@ -9024,11 +9017,10 @@ namespace libtorrent
} }
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
if ((*i)->on_pause()) return; if (ext->on_pause()) return;
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
#endif #endif
@ -9260,11 +9252,10 @@ namespace libtorrent
if (is_paused()) return; if (is_paused()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
if ((*i)->on_resume()) return; if (ext->on_resume()) return;
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
#endif #endif
@ -9492,11 +9483,10 @@ namespace libtorrent
boost::weak_ptr<torrent> self(shared_from_this()); boost::weak_ptr<torrent> self(shared_from_this());
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->tick(); ext->tick();
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
@ -11070,11 +11060,10 @@ namespace libtorrent
state_updated(); state_updated();
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_state(m_state); ext->on_state(m_state);
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
#endif #endif
@ -11084,11 +11073,10 @@ namespace libtorrent
void torrent::notify_extension_add_peer(tcp::endpoint const& ip void torrent::notify_extension_add_peer(tcp::endpoint const& ip
, int src, int flags) , int src, int flags)
{ {
for (extension_list_t::iterator i = m_extensions.begin() for (auto& ext : m_extensions)
, end(m_extensions.end()); i != end; ++i)
{ {
TORRENT_TRY { TORRENT_TRY {
(*i)->on_add_peer(ip, src, flags); ext->on_add_peer(ip, src, flags);
} TORRENT_CATCH (std::exception&) {} } TORRENT_CATCH (std::exception&) {}
} }
} }