mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-09 21:34:20 +00:00
Implement proper equal operators
This commit is contained in:
parent
d639c16f72
commit
94f7a095bb
@ -43,16 +43,6 @@ static const int ANNOUNCE_INTERVAL = 1800; // 30min
|
|||||||
using namespace BitTorrent;
|
using namespace BitTorrent;
|
||||||
|
|
||||||
// Peer
|
// Peer
|
||||||
bool Peer::operator!=(const Peer &other) const
|
|
||||||
{
|
|
||||||
return uid() != other.uid();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Peer::operator==(const Peer &other) const
|
|
||||||
{
|
|
||||||
return uid() == other.uid();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Peer::uid() const
|
QString Peer::uid() const
|
||||||
{
|
{
|
||||||
return ip.toString() + ':' + QString::number(port);
|
return ip.toString() + ':' + QString::number(port);
|
||||||
@ -69,6 +59,16 @@ lt::entry Peer::toEntry(const bool noPeerId) const
|
|||||||
return lt::entry(peerMap);
|
return lt::entry(peerMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BitTorrent::operator==(const Peer &left, const Peer &right)
|
||||||
|
{
|
||||||
|
return left.uid() == right.uid();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BitTorrent::operator!=(const Peer &left, const Peer &right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
|
|
||||||
// Tracker
|
// Tracker
|
||||||
|
|
||||||
Tracker::Tracker(QObject *parent)
|
Tracker::Tracker(QObject *parent)
|
||||||
|
@ -52,12 +52,13 @@ namespace BitTorrent
|
|||||||
QByteArray peerId;
|
QByteArray peerId;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
bool operator!=(const Peer &other) const;
|
|
||||||
bool operator==(const Peer &other) const;
|
|
||||||
QString uid() const;
|
QString uid() const;
|
||||||
lt::entry toEntry(bool noPeerId) const;
|
lt::entry toEntry(bool noPeerId) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator==(const Peer &left, const Peer &right);
|
||||||
|
bool operator!=(const Peer &left, const Peer &right);
|
||||||
|
|
||||||
struct TrackerAnnounceRequest
|
struct TrackerAnnounceRequest
|
||||||
{
|
{
|
||||||
QByteArray infoHash;
|
QByteArray infoHash;
|
||||||
|
@ -50,18 +50,18 @@ public:
|
|||||||
|
|
||||||
TriStateBool &operator=(const TriStateBool &other) = default; // add constexpr when using C++17
|
TriStateBool &operator=(const TriStateBool &other) = default; // add constexpr when using C++17
|
||||||
|
|
||||||
constexpr bool operator==(const TriStateBool &other) const
|
constexpr friend bool operator==(const TriStateBool &left, const TriStateBool &right)
|
||||||
{
|
{
|
||||||
return (m_value == other.m_value);
|
return (left.m_value == right.m_value);
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool operator!=(const TriStateBool &other) const
|
|
||||||
{
|
|
||||||
return !operator==(other);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
signed char m_value = -1; // Undefined by default
|
signed char m_value = -1; // Undefined by default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator!=(const TriStateBool &left, const TriStateBool &right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // TRISTATEBOOL_H
|
#endif // TRISTATEBOOL_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user