Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/subscription/UserDefinedSubscription.cpp

Issue 29574591: Issue 5258 - Implement Filter::As<>() method to make working with filters easier from C++ code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created Oct. 12, 2017, 12:13 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« compiled/filter/CommentFilter.h ('K') | « compiled/filter/WhitelistFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/subscription/UserDefinedSubscription.cpp
===================================================================
--- a/compiled/subscription/UserDefinedSubscription.cpp
+++ b/compiled/subscription/UserDefinedSubscription.cpp
@@ -25,56 +25,42 @@ namespace
enum FilterCategory
{
NONE = 0,
WHITELIST = 1,
BLOCKING = 2,
ELEMHIDE = 4,
};
- const FilterCategory filterTypeToCategory[] = {
- FilterCategory::BLOCKING, // UNKNOWN
- FilterCategory::NONE, // INVALID
- FilterCategory::NONE, // COMMENT
- FilterCategory::BLOCKING, // BLOCKING
- FilterCategory::WHITELIST, // WHITELIST
- FilterCategory::ELEMHIDE, // ELEMHIDE
- FilterCategory::ELEMHIDE, // ELEMHIDEEXCEPTION
- FilterCategory::ELEMHIDE, // ELEMHIDEEMULATION
- };
+ FilterCategory filterTypeToCategory(Filter::Type type)
+ {
+ if (type == Filter::Type::BLOCKING)
+ return FilterCategory::BLOCKING;
+ if (type == Filter::Type::WHITELIST)
+ return FilterCategory::WHITELIST;
+ if ((type & Filter::Type::ELEMHIDEBASE) == Filter::Type::ELEMHIDEBASE)
+ return FilterCategory::ELEMHIDE;
- static_assert(
- sizeof(filterTypeToCategory) / sizeof(filterTypeToCategory[0]) == Filter::Type::VALUE_COUNT,
- "Unexpected number of filter types, was a new type added?"
- );
+ return FilterCategory::NONE;
+ }
}
UserDefinedSubscription::UserDefinedSubscription(const String& id)
: Subscription(Type::USERDEFINED, id), mDefaults(0)
{
}
bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const
{
- if (filter.mType >= Filter::Type::VALUE_COUNT)
- {
- assert2(false, "Filter type exceeds valid range");
- abort();
- }
- return mDefaults & filterTypeToCategory[filter.mType];
+ return mDefaults & filterTypeToCategory(filter.mType);
}
void UserDefinedSubscription::MakeDefaultFor(const Filter& filter)
{
- if (filter.mType >= Filter::Type::VALUE_COUNT)
- {
- assert2(false, "Filter type exceeds valid range");
- abort();
- }
- mDefaults |= filterTypeToCategory[filter.mType];
+ mDefaults |= filterTypeToCategory(filter.mType);
}
void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos)
{
if (pos >= mFilters.size())
pos = mFilters.size();
mFilters.emplace(mFilters.begin() + pos, &filter);
« compiled/filter/CommentFilter.h ('K') | « compiled/filter/WhitelistFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld