From cbb6f47f362be2333615dc988a92424aad502184 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 4 Jul 2016 18:19:55 -0400 Subject: [PATCH] make some types movable (#885) --- include/libtorrent/session.hpp | 25 ++++++++++++++----------- include/libtorrent/session_handle.hpp | 8 ++++++++ include/libtorrent/torrent_handle.hpp | 8 +++----- src/session.cpp | 10 ++++++++++ 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index eec8cb351..779dd2957 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -117,21 +117,16 @@ namespace libtorrent public: // default constructor, does not refer to any session // implementation object. - session_proxy() {} + session_proxy(); ~session_proxy(); -#if __cplusplus >= 201103L - session_proxy(session_proxy const&) = default; - session_proxy& operator=(session_proxy const&) = default; -#endif + session_proxy(session_proxy const&); + session_proxy& operator=(session_proxy const&); private: session_proxy( boost::shared_ptr ios , std::shared_ptr t - , boost::shared_ptr impl) - : m_io_service(ios) - , m_thread(t) - , m_impl(impl) - {} + , boost::shared_ptr impl); + boost::shared_ptr m_io_service; std::shared_ptr m_thread; boost::shared_ptr m_impl; @@ -149,7 +144,7 @@ namespace libtorrent // the settings to be set and pass it in to ``session::apply_settings()``. // // see apply_settings(). - class TORRENT_EXPORT session: public boost::noncopyable, public session_handle + class TORRENT_EXPORT session : public session_handle { public: @@ -172,6 +167,14 @@ namespace libtorrent start(flags, pack, nullptr); } + // moveable + session(session&&) = default; + session& operator=(session&&) = default; + + // noncopyable + session(session const&) = delete; + session& operator=(session const&) = delete; + // overload of the constructor that takes an external io_service to run // the session object on. This is primarily useful for tests that may want // to run multiple sessions on a single io_service, or low resource diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index ea3c6fd07..fed9f3802 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -69,6 +69,14 @@ namespace libtorrent : m_impl(impl) {} + // moveable + session_handle(session_handle&&) = default; + session_handle& operator=(session_handle&&) = default; + + // non copyable + session_handle(session_handle const&) = delete; + session_handle& operator=(session_handle const&) = delete; + bool is_valid() const { return m_impl != nullptr; } // TODO: 2 the ip filter should probably be saved here too diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index a65c2943d..e0febfda7 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -248,12 +248,10 @@ namespace libtorrent // i.e. is_valid() will return false. torrent_handle() {} - torrent_handle(torrent_handle const& t) - { if (!t.m_torrent.expired()) m_torrent = t.m_torrent; } - -#if __cplusplus >= 201103L + torrent_handle(torrent_handle const& t) = default; + torrent_handle(torrent_handle&& t) = default; torrent_handle& operator=(torrent_handle const&) = default; -#endif + torrent_handle& operator=(torrent_handle&&) = default; // flags for add_piece(). enum flags_t { overwrite_existing = 1 }; diff --git a/src/session.cpp b/src/session.cpp index f741df06c..573552ae3 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -398,6 +398,16 @@ namespace libtorrent session_settings::~session_settings() {} #endif // TORRENT_NO_DEPRECATE + session_proxy::session_proxy() = default; + session_proxy::session_proxy(boost::shared_ptr ios + , std::shared_ptr t + , boost::shared_ptr impl) + : m_io_service(ios) + , m_thread(t) + , m_impl(impl) + {} + session_proxy::session_proxy(session_proxy const&) = default; + session_proxy& session_proxy::operator=(session_proxy const&) = default; session_proxy::~session_proxy() { if (m_thread && m_thread.unique())