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

Side by Side Diff: compiled/subscription/UserDefinedSubscription.cpp

Issue 29385742: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 2 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created March 16, 2017, 6:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "UserDefinedSubscription.h" 1 #include "UserDefinedSubscription.h"
2 2
3 int UserDefinedSubscription::filterTypeToDefaults[] = { 3 int UserDefinedSubscription::filterTypeToDefaults[] = {
4 UserDefinedSubscription::Defaults::BLOCKING, // UNKNOWN 4 UserDefinedSubscription::Defaults::BLOCKING, // UNKNOWN
5 UserDefinedSubscription::Defaults::BLOCKING, // INVALID 5 UserDefinedSubscription::Defaults::BLOCKING, // INVALID
6 UserDefinedSubscription::Defaults::BLOCKING, // COMMENT 6 UserDefinedSubscription::Defaults::BLOCKING, // COMMENT
7 UserDefinedSubscription::Defaults::BLOCKING, // BLOCKING 7 UserDefinedSubscription::Defaults::BLOCKING, // BLOCKING
8 UserDefinedSubscription::Defaults::WHITELIST, // WHITELIST 8 UserDefinedSubscription::Defaults::WHITELIST, // WHITELIST
9 UserDefinedSubscription::Defaults::ELEMHIDE, // ELEMHIDE 9 UserDefinedSubscription::Defaults::ELEMHIDE, // ELEMHIDE
10 UserDefinedSubscription::Defaults::ELEMHIDE, // ELEMHIDEEXCEPTION 10 UserDefinedSubscription::Defaults::ELEMHIDE, // ELEMHIDEEXCEPTION
11 UserDefinedSubscription::Defaults::ELEMHIDE, // ELEMHIDEEMULATION 11 UserDefinedSubscription::Defaults::ELEMHIDE, // ELEMHIDEEMULATION
12 }; 12 };
13 13
14 UserDefinedSubscription::UserDefinedSubscription(const String& id) 14 UserDefinedSubscription::UserDefinedSubscription(const String& id)
15 : Subscription(Type::USERDEFINED, id), mDefaults(0) 15 : Subscription(Type::USERDEFINED, id), mDefaults(0)
16 { 16 {
17 } 17 }
18 18
19 bool UserDefinedSubscription::IsDefaultFor(const Filter* filter) const 19 bool UserDefinedSubscription::IsDefaultFor(const Filter* filter) const
20 { 20 {
21 return mDefaults & filterTypeToDefaults[filter->mType]; 21 return mDefaults & filterTypeToDefaults[filter->mType];
22 } 22 }
23 23
24 void UserDefinedSubscription::MakeDefaultFor(const Filter* filter) 24 void UserDefinedSubscription::MakeDefaultFor(const Filter* filter)
25 { 25 {
26 mDefaults |= filterTypeToDefaults[filter->mType]; 26 mDefaults |= filterTypeToDefaults[filter->mType];
27 } 27 }
28 28
29 void UserDefinedSubscription::InsertFilterAt(Filter* filter, unsigned pos)
30 {
31 if (pos >= mFilters.size())
32 mFilters.emplace_back(filter);
33 else
34 mFilters.emplace(mFilters.begin() + pos, filter);
35 }
36
37 bool UserDefinedSubscription::RemoveFilterAt(unsigned pos)
38 {
39 if (pos >= mFilters.size())
40 return false;
41
42 mFilters.erase(mFilters.begin() + pos);
43 return true;
44 }
45
29 OwnedString UserDefinedSubscription::Serialize() const 46 OwnedString UserDefinedSubscription::Serialize() const
30 { 47 {
31 OwnedString result(Subscription::Serialize()); 48 OwnedString result(Subscription::Serialize());
32 if (mDefaults) 49 if (mDefaults)
33 { 50 {
34 result.append(u"defaults="_str); 51 result.append(u"defaults="_str);
35 if (mDefaults & Defaults::BLOCKING) 52 if (mDefaults & Defaults::BLOCKING)
36 result.append(u" blocking"_str); 53 result.append(u" blocking"_str);
37 if (mDefaults & Defaults::WHITELIST) 54 if (mDefaults & Defaults::WHITELIST)
38 result.append(u" whitelist"_str); 55 result.append(u" whitelist"_str);
39 if (mDefaults & Defaults::ELEMHIDE) 56 if (mDefaults & Defaults::ELEMHIDE)
40 result.append(u" elemhide"_str); 57 result.append(u" elemhide"_str);
41 result.append(u'\n'); 58 result.append(u'\n');
42 } 59 }
43 return result; 60 return result;
44 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld