LEFT | RIGHT |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #pragma once | 18 #pragma once |
19 | 19 |
| 20 #include <type_traits> |
20 #include <vector> | 21 #include <vector> |
21 | 22 |
22 #include "../filter/Filter.h" | 23 #include "../filter/Filter.h" |
23 #include "../String.h" | 24 #include "../String.h" |
24 #include "../intrusive_ptr.h" | 25 #include "../intrusive_ptr.h" |
25 #include "../debug.h" | 26 #include "../debug.h" |
26 | 27 |
27 #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");\ |
28 private:\ | 30 private:\ |
29 type name;\ | 31 type name;\ |
30 public:\ | 32 public:\ |
31 type EMSCRIPTEN_KEEPALIVE getter() const\ | 33 type EMSCRIPTEN_KEEPALIVE getter() const\ |
32 {\ | 34 {\ |
33 return name;\ | 35 return name;\ |
34 }\ | 36 }\ |
35 void EMSCRIPTEN_KEEPALIVE setter(type value)\ | 37 void EMSCRIPTEN_KEEPALIVE setter(type value)\ |
36 {\ | 38 {\ |
37 if (name != value)\ | 39 if (name != value)\ |
38 {\ | 40 {\ |
39 type oldvalue = name;\ | 41 type oldvalue = name;\ |
40 name = value;\ | 42 name = value;\ |
41 DependentString action(u"subscription."_str #name);\ | 43 DependentString action(u"subscription."_str #name);\ |
42 EM_ASM_ARGS({\ | 44 if (sizeof(type) <= 4)\ |
43 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | 45 {\ |
44 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4
);\ | 46 EM_ASM_ARGS({\ |
45 }, &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 }\ |
46 }\ | 58 }\ |
47 } | 59 } |
48 | 60 |
49 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ | 61 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ |
50 private:\ | 62 private:\ |
51 OwnedString name;\ | 63 OwnedString name;\ |
52 public:\ | 64 public:\ |
53 const String& EMSCRIPTEN_KEEPALIVE getter() const\ | 65 const String& EMSCRIPTEN_KEEPALIVE getter() const\ |
54 {\ | 66 {\ |
55 return name;\ | 67 return name;\ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 114 |
103 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); | 115 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); |
104 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); | 116 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); |
105 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; | 117 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; |
106 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; | 118 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; |
107 | 119 |
108 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); | 120 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); |
109 }; | 121 }; |
110 | 122 |
111 typedef intrusive_ptr<Subscription> SubscriptionPtr; | 123 typedef intrusive_ptr<Subscription> SubscriptionPtr; |
LEFT | RIGHT |