Browse Source

Use `underlying_type` member directly

`LTUnderlyingType` served as a intermediate type for libtorrent 1.1 and
1.2 and is obsoleted now.
Also add helper to convert to underlying type.
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
7c23d800e6
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 29
      src/base/bittorrent/ltunderlyingtype.h
  2. 22
      src/base/bittorrent/session.cpp
  3. 2
      src/base/bittorrent/torrentcreatorthread.cpp
  4. 12
      src/base/bittorrent/torrentimpl.cpp

29
src/base/bittorrent/ltunderlyingtype.h

@ -28,31 +28,8 @@ @@ -28,31 +28,8 @@
#pragma once
#include <type_traits>
template <typename T, typename = void>
struct HasUnderlyingType
: std::false_type
{
};
template <typename T>
struct HasUnderlyingType<T, std::void_t<typename T::underlying_type>>
: std::true_type
{
};
template <typename T, typename = void>
struct LTUnderlying
{
using type = T;
};
template <typename T>
struct LTUnderlying<T, typename std::enable_if_t<HasUnderlyingType<T>::value>>
typename T::underlying_type toLTUnderlyingType(const T &t)
{
using type = typename T::underlying_type;
};
template <typename T>
using LTUnderlyingType = typename LTUnderlying<T>::type;
return static_cast<typename T::underlying_type>(t);
}

22
src/base/bittorrent/session.cpp

@ -1489,7 +1489,7 @@ void Session::configurePeerClasses() @@ -1489,7 +1489,7 @@ void Session::configurePeerClasses()
// Proactively do the same for 0.0.0.0 and address_v4::any()
f.add_rule(lt::address_v4::any()
, lt::address_v4::broadcast()
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::global_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::global_peer_class_id));
// IPv6 may not be available on OS and the parsing
// would result in an exception -> abnormal program termination
@ -1498,7 +1498,7 @@ void Session::configurePeerClasses() @@ -1498,7 +1498,7 @@ void Session::configurePeerClasses()
{
f.add_rule(lt::address_v6::any()
, lt::make_address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::global_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::global_peer_class_id));
}
catch (const std::exception &) {}
@ -1507,21 +1507,21 @@ void Session::configurePeerClasses() @@ -1507,21 +1507,21 @@ void Session::configurePeerClasses()
// local networks
f.add_rule(lt::make_address("10.0.0.0")
, lt::make_address("10.255.255.255")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
f.add_rule(lt::make_address("172.16.0.0")
, lt::make_address("172.31.255.255")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
f.add_rule(lt::make_address("192.168.0.0")
, lt::make_address("192.168.255.255")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
// link local
f.add_rule(lt::make_address("169.254.0.0")
, lt::make_address("169.254.255.255")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
// loopback
f.add_rule(lt::make_address("127.0.0.0")
, lt::make_address("127.255.255.255")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
// IPv6 may not be available on OS and the parsing
// would result in an exception -> abnormal program termination
@ -1531,15 +1531,15 @@ void Session::configurePeerClasses() @@ -1531,15 +1531,15 @@ void Session::configurePeerClasses()
// link local
f.add_rule(lt::make_address("fe80::")
, lt::make_address("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
// unique local addresses
f.add_rule(lt::make_address("fc00::")
, lt::make_address("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
// loopback
f.add_rule(lt::address_v6::loopback()
, lt::address_v6::loopback()
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
, 1 << toLTUnderlyingType(lt::session::local_peer_class_id));
}
catch (const std::exception &) {}
}
@ -2377,7 +2377,7 @@ void Session::saveTorrentsQueue() const @@ -2377,7 +2377,7 @@ void Session::saveTorrentsQueue() const
for (const TorrentImpl *torrent : asConst(m_torrents))
{
// We require actual (non-cached) queue position here!
const int queuePos = static_cast<LTUnderlyingType<lt::queue_position_t>>(torrent->nativeHandle().queue_position());
const int queuePos = toLTUnderlyingType(torrent->nativeHandle().queue_position());
if (queuePos >= 0)
{
if (queuePos >= queue.size())

2
src/base/bittorrent/torrentcreatorthread.cpp

@ -188,7 +188,7 @@ void TorrentCreatorThread::run() @@ -188,7 +188,7 @@ void TorrentCreatorThread::run()
, [this, &newTorrent](const lt::piece_index_t n)
{
checkInterruptionRequested();
sendProgressSignal(static_cast<LTUnderlyingType<lt::piece_index_t>>(n), newTorrent.num_pieces());
sendProgressSignal(toLTUnderlyingType(n), newTorrent.num_pieces());
});
// Set qBittorrent as creator and add user comment to

12
src/base/bittorrent/torrentimpl.cpp

@ -84,7 +84,7 @@ namespace @@ -84,7 +84,7 @@ namespace
, std::back_inserter(out), [](const DownloadPriority priority)
{
return static_cast<lt::download_priority_t>(
static_cast<LTUnderlyingType<lt::download_priority_t>>(priority));
static_cast<lt::download_priority_t::underlying_type>(priority));
});
return out;
}
@ -799,7 +799,7 @@ QVector<DownloadPriority> TorrentImpl::filePriorities() const @@ -799,7 +799,7 @@ QVector<DownloadPriority> TorrentImpl::filePriorities() const
QVector<DownloadPriority> ret;
std::transform(fp.cbegin(), fp.cend(), std::back_inserter(ret), [](lt::download_priority_t priority)
{
return static_cast<DownloadPriority>(static_cast<LTUnderlyingType<lt::download_priority_t>>(priority));
return static_cast<DownloadPriority>(toLTUnderlyingType(priority));
});
return ret;
}
@ -1250,7 +1250,7 @@ QBitArray TorrentImpl::downloadingPieces() const @@ -1250,7 +1250,7 @@ QBitArray TorrentImpl::downloadingPieces() const
m_nativeHandle.get_download_queue(queue);
for (const lt::partial_piece_info &info : queue)
result.setBit(static_cast<LTUnderlyingType<lt::piece_index_t>>(info.piece_index));
result.setBit(toLTUnderlyingType(info.piece_index));
return result;
}
@ -1900,7 +1900,7 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p) @@ -1900,7 +1900,7 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p)
void TorrentImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p)
{
LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"")
.arg(name(), filePath(static_cast<LTUnderlyingType<lt::file_index_t>>(p->index))
.arg(name(), filePath(toLTUnderlyingType(p->index))
, QString::fromLocal8Bit(p->error.message().c_str())), Log::WARNING);
m_oldPath[p->index].removeFirst();
@ -1919,13 +1919,13 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p) @@ -1919,13 +1919,13 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p)
qDebug("A file completed download in torrent \"%s\"", qUtf8Printable(name()));
if (m_session->isAppendExtensionEnabled())
{
QString name = filePath(static_cast<LTUnderlyingType<lt::file_index_t>>(p->index));
QString name = filePath(toLTUnderlyingType(p->index));
if (name.endsWith(QB_EXT))
{
const QString oldName = name;
name.chop(QB_EXT.size());
qDebug("Renaming %s to %s", qUtf8Printable(oldName), qUtf8Printable(name));
renameFile(static_cast<LTUnderlyingType<lt::file_index_t>>(p->index), name);
renameFile(toLTUnderlyingType(p->index), name);
}
}
}

Loading…
Cancel
Save