LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
1 #pragma once | 18 #pragma once |
2 | 19 |
| 20 #include <type_traits> |
3 #include <vector> | 21 #include <vector> |
4 | 22 |
5 #include "../filter/Filter.h" | 23 #include "../filter/Filter.h" |
6 #include "../String.h" | 24 #include "../String.h" |
7 #include "../intrusive_ptr.h" | 25 #include "../intrusive_ptr.h" |
8 #include "../debug.h" | 26 #include "../debug.h" |
9 | 27 |
10 #define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \ | 28 #define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \ |
| 29 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro
can only be used with arithmetic types");\ |
11 private:\ | 30 private:\ |
12 type name;\ | 31 type name;\ |
13 public:\ | 32 public:\ |
14 type EMSCRIPTEN_KEEPALIVE getter() const\ | 33 type EMSCRIPTEN_KEEPALIVE getter() const\ |
15 {\ | 34 {\ |
16 return name;\ | 35 return name;\ |
17 }\ | 36 }\ |
18 void EMSCRIPTEN_KEEPALIVE setter(type value)\ | 37 void EMSCRIPTEN_KEEPALIVE setter(type value)\ |
19 {\ | 38 {\ |
20 if (name != value)\ | 39 if (name != value)\ |
21 {\ | 40 {\ |
22 type oldvalue = name;\ | 41 type oldvalue = name;\ |
23 name = value;\ | 42 name = value;\ |
24 DependentString action(u"subscription."_str #name);\ | 43 DependentString action(u"subscription."_str #name);\ |
25 EM_ASM_ARGS({\ | 44 if (sizeof(type) <= 4)\ |
26 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | 45 {\ |
27 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4
);\ | 46 EM_ASM_ARGS({\ |
28 }, &action, this, mType, value, oldvalue);\ | 47 var subscription = new (exports[Subscription_mapping[$2]])($1);\ |
| 48 FilterNotifier.triggerListeners(readString($0), subscription, $3,
$4);\ |
| 49 }, &action, this, mType, value, oldvalue);\ |
| 50 }\ |
| 51 else\ |
| 52 {\ |
| 53 EM_ASM_ARGS({\ |
| 54 var subscription = new (exports[Subscription_mapping[$2]])($1);\ |
| 55 FilterNotifier.triggerListeners(readString($0), subscription, $3,
$4);\ |
| 56 }, &action, this, mType, (double)value, (double)oldvalue);\ |
| 57 }\ |
29 }\ | 58 }\ |
30 } | 59 } |
31 | 60 |
32 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ | 61 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ |
33 private:\ | 62 private:\ |
34 OwnedString name;\ | 63 OwnedString name;\ |
35 public:\ | 64 public:\ |
36 const String& EMSCRIPTEN_KEEPALIVE getter() const\ | 65 const String& EMSCRIPTEN_KEEPALIVE getter() const\ |
37 {\ | 66 {\ |
38 return name;\ | 67 return name;\ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 114 |
86 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); | 115 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); |
87 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); | 116 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); |
88 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; | 117 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; |
89 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; | 118 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; |
90 | 119 |
91 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); | 120 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); |
92 }; | 121 }; |
93 | 122 |
94 typedef intrusive_ptr<Subscription> SubscriptionPtr; | 123 typedef intrusive_ptr<Subscription> SubscriptionPtr; |
LEFT | RIGHT |