mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Merge pull request #11259 from Chocobo1/tristate
Revise TriStateBool class
This commit is contained in:
commit
7c7963f93f
@ -64,7 +64,7 @@ namespace
|
||||
|
||||
QJsonValue triStateBoolToJsonValue(const TriStateBool &triStateBool)
|
||||
{
|
||||
switch (static_cast<int>(triStateBool)) {
|
||||
switch (static_cast<signed char>(triStateBool)) {
|
||||
case 0: return false;
|
||||
case 1: return true;
|
||||
default: return {};
|
||||
@ -82,7 +82,7 @@ namespace
|
||||
|
||||
int triStateBoolToAddPausedLegacy(const TriStateBool &triStateBool)
|
||||
{
|
||||
switch (static_cast<int>(triStateBool)) {
|
||||
switch (static_cast<signed char>(triStateBool)) {
|
||||
case 0: return 2; // never
|
||||
case 1: return 1; // always
|
||||
default: return 0; // default
|
||||
|
@ -38,24 +38,29 @@ public:
|
||||
|
||||
constexpr TriStateBool() = default;
|
||||
constexpr TriStateBool(const TriStateBool &other) = default;
|
||||
explicit constexpr TriStateBool(int value)
|
||||
: m_value(value < 0 ? -1 : (value > 0 ? 1 : 0))
|
||||
explicit constexpr TriStateBool(const bool boolean)
|
||||
{
|
||||
*this = boolean ? True : False;
|
||||
}
|
||||
|
||||
explicit constexpr operator int() const
|
||||
TriStateBool &operator=(const TriStateBool &other) = default; // TODO: add constexpr when using C++17
|
||||
|
||||
explicit constexpr operator signed char() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
TriStateBool &operator=(const TriStateBool &other) = default; // add constexpr when using C++17
|
||||
|
||||
constexpr friend bool operator==(const TriStateBool &left, const TriStateBool &right)
|
||||
{
|
||||
return (left.m_value == right.m_value);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit constexpr TriStateBool(const int value)
|
||||
: m_value((value < 0) ? -1 : ((value > 0) ? 1 : 0))
|
||||
{
|
||||
}
|
||||
|
||||
signed char m_value = -1; // Undefined by default
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user