Browse Source

Merge pull request #11259 from Chocobo1/tristate

Revise TriStateBool class
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
7c7963f93f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/base/rss/rss_autodownloadrule.cpp
  2. 15
      src/base/tristatebool.h

4
src/base/rss/rss_autodownloadrule.cpp

@ -64,7 +64,7 @@ namespace
QJsonValue triStateBoolToJsonValue(const TriStateBool &triStateBool) QJsonValue triStateBoolToJsonValue(const TriStateBool &triStateBool)
{ {
switch (static_cast<int>(triStateBool)) { switch (static_cast<signed char>(triStateBool)) {
case 0: return false; case 0: return false;
case 1: return true; case 1: return true;
default: return {}; default: return {};
@ -82,7 +82,7 @@ namespace
int triStateBoolToAddPausedLegacy(const TriStateBool &triStateBool) int triStateBoolToAddPausedLegacy(const TriStateBool &triStateBool)
{ {
switch (static_cast<int>(triStateBool)) { switch (static_cast<signed char>(triStateBool)) {
case 0: return 2; // never case 0: return 2; // never
case 1: return 1; // always case 1: return 1; // always
default: return 0; // default default: return 0; // default

15
src/base/tristatebool.h

@ -38,24 +38,29 @@ public:
constexpr TriStateBool() = default; constexpr TriStateBool() = default;
constexpr TriStateBool(const TriStateBool &other) = default; constexpr TriStateBool(const TriStateBool &other) = default;
explicit constexpr TriStateBool(int value) explicit constexpr TriStateBool(const bool boolean)
: m_value(value < 0 ? -1 : (value > 0 ? 1 : 0))
{ {
*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; 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) constexpr friend bool operator==(const TriStateBool &left, const TriStateBool &right)
{ {
return (left.m_value == right.m_value); return (left.m_value == right.m_value);
} }
private: private:
explicit constexpr TriStateBool(const int value)
: m_value((value < 0) ? -1 : ((value > 0) ? 1 : 0))
{
}
signed char m_value = -1; // Undefined by default signed char m_value = -1; // Undefined by default
}; };

Loading…
Cancel
Save