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

Delta Between Two Patch Sets: compiled/subscription/UserDefinedSubscription.cpp

Issue 29613616: Issue 6064 - Put C++ code into a configurable namespace (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Left Patch Set: address comments Created Nov. 22, 2017, 9:36 a.m.
Right Patch Set: rebase Created Feb. 6, 2018, 9:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 14 matching lines...) Expand all
25 namespace 25 namespace
26 { 26 {
27 enum FilterCategory 27 enum FilterCategory
28 { 28 {
29 NONE = 0, 29 NONE = 0,
30 WHITELIST = 1, 30 WHITELIST = 1,
31 BLOCKING = 2, 31 BLOCKING = 2,
32 ELEMHIDE = 4, 32 ELEMHIDE = 4,
33 }; 33 };
34 34
35 const FilterCategory filterTypeToCategory[] = { 35 FilterCategory filterTypeToCategory(Filter::Type type)
36 FilterCategory::BLOCKING, // UNKNOWN 36 {
37 FilterCategory::NONE, // INVALID 37 if (type == Filter::Type::BLOCKING)
38 FilterCategory::NONE, // COMMENT 38 return FilterCategory::BLOCKING;
39 FilterCategory::BLOCKING, // BLOCKING 39 if (type == Filter::Type::WHITELIST)
40 FilterCategory::WHITELIST, // WHITELIST 40 return FilterCategory::WHITELIST;
41 FilterCategory::ELEMHIDE, // ELEMHIDE 41 if ((type & Filter::Type::ELEMHIDEBASE) == Filter::Type::ELEMHIDEBASE)
42 FilterCategory::ELEMHIDE, // ELEMHIDEEXCEPTION 42 return FilterCategory::ELEMHIDE;
43 FilterCategory::ELEMHIDE, // ELEMHIDEEMULATION
44 };
45 43
46 static_assert( 44 return FilterCategory::NONE;
47 sizeof(filterTypeToCategory) / sizeof(filterTypeToCategory[0]) == Filter::Ty pe::VALUE_COUNT, 45 }
48 "Unexpected number of filter types, was a new type added?"
49 );
50 } 46 }
51 47
52 UserDefinedSubscription::UserDefinedSubscription(const String& id) 48 UserDefinedSubscription::UserDefinedSubscription(const String& id)
53 : Subscription(Type::USERDEFINED, id), mDefaults(0) 49 : Subscription(classType, id), mDefaults(0)
54 { 50 {
55 } 51 }
56 52
57 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const 53 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const
58 { 54 {
59 if (filter.mType >= Filter::Type::VALUE_COUNT) 55 return mDefaults & filterTypeToCategory(filter.mType);
60 {
61 assert2(false, u"Filter type exceeds valid range"_str);
62 abort();
63 }
64 return mDefaults & filterTypeToCategory[filter.mType];
65 } 56 }
66 57
67 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter) 58 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter)
68 { 59 {
69 if (filter.mType >= Filter::Type::VALUE_COUNT) 60 mDefaults |= filterTypeToCategory(filter.mType);
70 {
71 assert2(false, u"Filter type exceeds valid range"_str);
72 abort();
73 }
74 mDefaults |= filterTypeToCategory[filter.mType];
75 } 61 }
76 62
77 void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos) 63 void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos)
78 { 64 {
79 if (pos >= mFilters.size()) 65 if (pos >= mFilters.size())
80 pos = mFilters.size(); 66 pos = mFilters.size();
81 mFilters.emplace(mFilters.begin() + pos, &filter); 67 mFilters.emplace(mFilters.begin() + pos, &filter);
82 68
83 if (GetListed()) 69 if (GetListed())
84 { 70 {
(...skipping 26 matching lines...) Expand all
111 if (mDefaults & FilterCategory::BLOCKING) 97 if (mDefaults & FilterCategory::BLOCKING)
112 result.append(u" blocking"_str); 98 result.append(u" blocking"_str);
113 if (mDefaults & FilterCategory::WHITELIST) 99 if (mDefaults & FilterCategory::WHITELIST)
114 result.append(u" whitelist"_str); 100 result.append(u" whitelist"_str);
115 if (mDefaults & FilterCategory::ELEMHIDE) 101 if (mDefaults & FilterCategory::ELEMHIDE)
116 result.append(u" elemhide"_str); 102 result.append(u" elemhide"_str);
117 result.append(u'\n'); 103 result.append(u'\n');
118 } 104 }
119 return result; 105 return result;
120 } 106 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld