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

Side by Side Diff: compiled/subscription/Subscription.h

Issue 29384812: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 1 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Addressed comments Created April 13, 2017, 1:02 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
(Empty)
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
18 #pragma once
19
20 #include <type_traits>
21 #include <vector>
22
23 #include "../filter/Filter.h"
24 #include "../String.h"
25 #include "../intrusive_ptr.h"
26 #include "../debug.h"
27
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");\
30 private:\
31 type name;\
32 public:\
33 type EMSCRIPTEN_KEEPALIVE getter() const\
34 {\
35 return name;\
36 }\
37 void EMSCRIPTEN_KEEPALIVE setter(type value)\
38 {\
39 if (name != value)\
40 {\
41 type oldvalue = name;\
42 name = value;\
43 DependentString action(u"subscription."_str #name);\
44 if (sizeof(type) <= 4)\
45 {\
46 EM_ASM_ARGS({\
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 }\
58 }\
59 }
60
61 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \
62 private:\
63 OwnedString name;\
64 public:\
65 const String& EMSCRIPTEN_KEEPALIVE getter() const\
66 {\
67 return name;\
68 }\
69 void EMSCRIPTEN_KEEPALIVE setter(const String& value)\
70 {\
71 if (!name.equals(value))\
72 {\
73 OwnedString oldvalue(name);\
74 name = value;\
75 DependentString action(u"subscription."_str #name);\
76 EM_ASM_ARGS({\
77 var subscription = new (exports[Subscription_mapping[$2]])($1);\
78 FilterNotifier.triggerListeners(readString($0), subscription, readSt ring($3), readString($4));\
79 }, &action, this, mType, &value, &oldvalue);\
80 }\
81 }
82
83 class Subscription : public ref_counted
84 {
85 protected:
86 OwnedString mID;
87 std::vector<Filter> mFilters;
88
89 public:
90 enum Type
91 {
92 UNKNOWN = 0,
93 DOWNLOADABLE = 1,
94 USERDEFINED = 2
95 };
96
97 explicit Subscription(Type type, const String& id);
98 ~Subscription();
99
100 Type mType;
101
102 EMSCRIPTEN_KEEPALIVE const String& GetID() const
103 {
104 return mID;
105 }
106
107 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle);
108 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled);
109
110 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const;
111 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const;
112
113 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id);
114 };
115
116 typedef intrusive_ptr<Subscription> SubscriptionPtr;
OLDNEW
« no previous file with comments | « compiled/subscription/DownloadableSubscription.cpp ('k') | compiled/subscription/Subscription.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld