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

9
src/base/indexrange.h

@ -101,14 +101,15 @@ public:
return iter; 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: private:

52
src/base/rss/rss_autodownloadrule.cpp

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

8
src/base/rss/rss_autodownloadrule.h

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

Loading…
Cancel
Save