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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/subscription/DownloadableSubscription.cpp ('k') | compiled/subscription/Subscription.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/subscription/Subscription.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/subscription/Subscription.h
@@ -0,0 +1,116 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2017 eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <type_traits>
+#include <vector>
+
+#include "../filter/Filter.h"
+#include "../String.h"
+#include "../intrusive_ptr.h"
+#include "../debug.h"
+
+#define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \
+ static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\
+ private:\
+ type name;\
+ public:\
+ type EMSCRIPTEN_KEEPALIVE getter() const\
+ {\
+ return name;\
+ }\
+ void EMSCRIPTEN_KEEPALIVE setter(type value)\
+ {\
+ if (name != value)\
+ {\
+ type oldvalue = name;\
+ name = value;\
+ DependentString action(u"subscription."_str #name);\
+ if (sizeof(type) <= 4)\
+ {\
+ EM_ASM_ARGS({\
+ var subscription = new (exports[Subscription_mapping[$2]])($1);\
+ FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\
+ }, &action, this, mType, value, oldvalue);\
+ }\
+ else\
+ {\
+ EM_ASM_ARGS({\
+ var subscription = new (exports[Subscription_mapping[$2]])($1);\
+ FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\
+ }, &action, this, mType, (double)value, (double)oldvalue);\
+ }\
+ }\
+ }
+
+#define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \
+ private:\
+ OwnedString name;\
+ public:\
+ const String& EMSCRIPTEN_KEEPALIVE getter() const\
+ {\
+ return name;\
+ }\
+ void EMSCRIPTEN_KEEPALIVE setter(const String& value)\
+ {\
+ if (!name.equals(value))\
+ {\
+ OwnedString oldvalue(name);\
+ name = value;\
+ DependentString action(u"subscription."_str #name);\
+ EM_ASM_ARGS({\
+ var subscription = new (exports[Subscription_mapping[$2]])($1);\
+ FilterNotifier.triggerListeners(readString($0), subscription, readString($3), readString($4));\
+ }, &action, this, mType, &value, &oldvalue);\
+ }\
+ }
+
+class Subscription : public ref_counted
+{
+protected:
+ OwnedString mID;
+ std::vector<Filter> mFilters;
+
+public:
+ enum Type
+ {
+ UNKNOWN = 0,
+ DOWNLOADABLE = 1,
+ USERDEFINED = 2
+ };
+
+ explicit Subscription(Type type, const String& id);
+ ~Subscription();
+
+ Type mType;
+
+ EMSCRIPTEN_KEEPALIVE const String& GetID() const
+ {
+ return mID;
+ }
+
+ SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle);
+ SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled);
+
+ EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const;
+ EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const;
+
+ static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id);
+};
+
+typedef intrusive_ptr<Subscription> SubscriptionPtr;
« 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