Browse Source

Move comparison operator out of class

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
39c34078d6
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 56
      src/app/cmdoptions.cpp
  2. 9
      src/base/indexrange.h
  3. 52
      src/base/rss/rss_autodownloadrule.cpp
  4. 8
      src/base/rss/rss_autodownloadrule.h

56
src/app/cmdoptions.cpp

@ -111,12 +111,6 @@ namespace @@ -111,12 +111,6 @@ namespace
{
}
bool operator==(const QString &arg) const
{
return (hasShortcut() && ((arg.size() == 2) && (arg == shortcutParameter())))
|| (arg == fullParameter());
}
bool value(const QProcessEnvironment &env) const
{
QString val = env.value(envVarName());
@ -132,11 +126,17 @@ namespace @@ -132,11 +126,17 @@ namespace
res += fullParameter();
return padUsageText(res);
}
friend bool operator==(const BoolOption &option, const QString &arg)
{
return (option.hasShortcut() && ((arg.size() == 2) && (option.shortcutParameter() == arg)))
|| (option.fullParameter() == arg);
}
};
bool operator==(const QString &s, const BoolOption &o)
bool operator==(const QString &arg, const BoolOption &option)
{
return o == s;
return (option == arg);
}
// Option with string value. May not have a shortcut
@ -148,11 +148,6 @@ namespace @@ -148,11 +148,6 @@ namespace
{
}
bool operator==(const QString &arg) const
{
return arg.startsWith(parameterAssignment());
}
QString value(const QString &arg) const
{
QStringList parts = arg.split(u'=');
@ -174,6 +169,11 @@ namespace @@ -174,6 +169,11 @@ namespace
return padUsageText(parameterAssignment() + u'<' + valueName + u'>');
}
friend bool operator==(const StringOption &option, const QString &arg)
{
return arg.startsWith(option.parameterAssignment());
}
private:
QString parameterAssignment() const
{
@ -181,9 +181,9 @@ namespace @@ -181,9 +181,9 @@ namespace
}
};
bool operator==(const QString &s, const StringOption &o)
bool operator==(const QString &arg, const StringOption &option)
{
return o == s;
return (option == arg);
}
// Option with integer value. May not have a shortcut
@ -195,7 +195,6 @@ namespace @@ -195,7 +195,6 @@ namespace
{
}
using StringOption::operator==;
using StringOption::usage;
int value(const QString &arg) const
@ -225,11 +224,16 @@ namespace @@ -225,11 +224,16 @@ namespace
}
return res;
}
friend bool operator==(const IntOption &option, const QString &arg)
{
return (static_cast<StringOption>(option) == arg);
}
};
bool operator==(const QString &s, const IntOption &o)
bool operator==(const QString &arg, const IntOption &option)
{
return o == s;
return (option == arg);
}
// Option that is explicitly set to true or false, and whose value is undefined when unspecified.
@ -243,12 +247,6 @@ namespace @@ -243,12 +247,6 @@ namespace
{
}
bool operator==(const QString &arg) const
{
QStringList parts = arg.split(u'=');
return parts[0] == fullParameter();
}
QString usage() const
{
return padUsageText(fullParameter() + u"=<true|false>");
@ -308,12 +306,18 @@ namespace @@ -308,12 +306,18 @@ namespace
return std::nullopt;
}
friend bool operator==(const TriStateBoolOption &option, const QString &arg)
{
const QStringList parts = arg.split(u'=');
return parts[0] == option.fullParameter();
}
bool m_defaultValue;
};
bool operator==(const QString &s, const TriStateBoolOption &o)
bool operator==(const QString &arg, const TriStateBoolOption &option)
{
return o == s;
return (option == arg);
}
constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'};

9
src/base/indexrange.h

@ -101,14 +101,15 @@ public: @@ -101,14 +101,15 @@ public:
return iter;
}
constexpr bool operator==(const Iterator &other) const
// comparing iterators from different containers is undefined behavior in C++ standard library
friend constexpr bool operator==(const Iterator &left, const Iterator &right)
{
return (*(*this) == *other);
return (*left == *right);
}
constexpr bool operator!=(const Iterator &other) const
friend constexpr bool operator!=(const Iterator &left, const Iterator &right)
{
return !(*this == other);
return !(left == right);
}
private:

52
src/base/rss/rss_autodownloadrule.cpp

@ -144,24 +144,35 @@ namespace RSS @@ -144,24 +144,35 @@ namespace RSS
mutable QStringList lastComputedEpisodes;
mutable QHash<QString, QRegularExpression> cachedRegexes;
bool operator==(const AutoDownloadRuleData &other) const
friend bool operator==(const AutoDownloadRuleData &left, const AutoDownloadRuleData &right)
{
return (name == other.name)
&& (enabled == other.enabled)
&& (mustContain == other.mustContain)
&& (mustNotContain == other.mustNotContain)
&& (episodeFilter == other.episodeFilter)
&& (feedURLs == other.feedURLs)
&& (useRegex == other.useRegex)
&& (ignoreDays == other.ignoreDays)
&& (lastMatch == other.lastMatch)
&& (savePath == other.savePath)
&& (category == other.category)
&& (addPaused == other.addPaused)
&& (contentLayout == other.contentLayout)
&& (smartFilter == other.smartFilter);
return (left.name == right.name)
&& (left.enabled == right.enabled)
&& (left.mustContain == right.mustContain)
&& (left.mustNotContain == right.mustNotContain)
&& (left.episodeFilter == right.episodeFilter)
&& (left.feedURLs == right.feedURLs)
&& (left.useRegex == right.useRegex)
&& (left.ignoreDays == right.ignoreDays)
&& (left.lastMatch == right.lastMatch)
&& (left.savePath == right.savePath)
&& (left.category == right.category)
&& (left.addPaused == right.addPaused)
&& (left.contentLayout == right.contentLayout)
&& (left.smartFilter == right.smartFilter);
}
};
bool operator==(const AutoDownloadRule &left, const AutoDownloadRule &right)
{
return (left.m_dataPtr == right.m_dataPtr) // optimization
|| (*(left.m_dataPtr) == *(right.m_dataPtr));
}
bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right)
{
return !(left == right);
}
}
using namespace RSS;
@ -448,17 +459,6 @@ AutoDownloadRule &AutoDownloadRule::operator=(const AutoDownloadRule &other) @@ -448,17 +459,6 @@ AutoDownloadRule &AutoDownloadRule::operator=(const AutoDownloadRule &other)
return *this;
}
bool AutoDownloadRule::operator==(const AutoDownloadRule &other) const
{
return (m_dataPtr == other.m_dataPtr) // optimization
|| (*m_dataPtr == *other.m_dataPtr);
}
bool AutoDownloadRule::operator!=(const AutoDownloadRule &other) const
{
return !operator==(other);
}
QJsonObject AutoDownloadRule::toJsonObject() const
{
return {{Str_Enabled, isEnabled()}

8
src/base/rss/rss_autodownloadrule.h

@ -53,6 +53,8 @@ namespace RSS @@ -53,6 +53,8 @@ namespace RSS
AutoDownloadRule(const AutoDownloadRule &other);
~AutoDownloadRule();
AutoDownloadRule &operator=(const AutoDownloadRule &other);
QString name() const;
void setName(const QString &name);
@ -91,9 +93,7 @@ namespace RSS @@ -91,9 +93,7 @@ namespace RSS
bool matches(const QVariantHash &articleData) const;
bool accepts(const QVariantHash &articleData);
AutoDownloadRule &operator=(const AutoDownloadRule &other);
bool operator==(const AutoDownloadRule &other) const;
bool operator!=(const AutoDownloadRule &other) const;
friend bool operator==(const AutoDownloadRule &left, const AutoDownloadRule &right);
QJsonObject toJsonObject() const;
static AutoDownloadRule fromJsonObject(const QJsonObject &jsonObj, const QString &name = u""_qs);
@ -111,4 +111,6 @@ namespace RSS @@ -111,4 +111,6 @@ namespace RSS
QSharedDataPointer<AutoDownloadRuleData> m_dataPtr;
};
bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right);
}

Loading…
Cancel
Save