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

Delta Between Two Patch Sets: compiled/subscription/Subscription.h

Issue 29548581: Issue 4128, 5138 - Add Parser and Serializer implemented in C++ Base URL: https://github.com/adblockplus/adblockpluscore.git
Left Patch Set: Created Sept. 18, 2017, 5:23 p.m.
Right Patch Set: rebase Created March 7, 2018, 12:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/subscription/DownloadableSubscription.cpp ('k') | compiled/subscription/Subscription.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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>
21 #include <vector> 20 #include <vector>
22 21
22 #include "../base.h"
23 #include "../filter/Filter.h" 23 #include "../filter/Filter.h"
24 #include "../String.h" 24 #include "../String.h"
25 #include "../FilterNotifier.h" 25 #include "../FilterNotifier.h"
26 #include "../intrusive_ptr.h" 26 #include "../intrusive_ptr.h"
27 #include "../debug.h" 27 #include "../debug.h"
28 #include "../bindings/runtime.h" 28 #include "../bindings/runtime.h"
29 29
30 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett er, setter) \ 30 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett er, setter) \
31 private:\ 31 private:\
32 field_type name;\ 32 field_type name;\
33 public:\ 33 public:\
34 param_type BINDINGS_EXPORTED getter() const\ 34 param_type BINDINGS_EXPORTED getter() const\
35 {\ 35 {\
36 return name;\ 36 return name;\
37 }\ 37 }\
38 void BINDINGS_EXPORTED setter(param_type value)\ 38 void BINDINGS_EXPORTED setter(param_type value)\
39 {\ 39 {\
40 if (name != value)\ 40 if (name != value)\
41 {\ 41 {\
42 name = value;\ 42 name = value;\
43 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\ 43 if (ABP_NS::FilterNotifier::Topic::topic != ABP_NS::FilterNotifier::To pic::NONE)\
44 {\ 44 {\
45 FilterNotifier::SubscriptionChange(FilterNotifier::Topic::topic,\ 45 ABP_NS::FilterNotifier::SubscriptionChange(ABP_NS::FilterNotifier::T opic::topic,\
46 *this);\ 46 *this);\
47 }\ 47 }\
48 }\ 48 }\
49 } 49 }
50 50
51 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \ 51 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \
52 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\ 52 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\
53 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter) 53 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter)
54 54
55 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \ 55 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \
56 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett er, setter) 56 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett er, setter)
57
58 ABP_NS_BEGIN
57 59
58 class Subscription; 60 class Subscription;
59 typedef intrusive_ptr<Subscription> SubscriptionPtr; 61 typedef intrusive_ptr<Subscription> SubscriptionPtr;
60 62
61 class Subscription : public ref_counted 63 class Subscription : public ref_counted
62 { 64 {
63 public: 65 public:
64 typedef std::vector<FilterPtr> Filters; 66 typedef std::vector<FilterPtr> Filters;
65 67
66 protected: 68 protected:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter); 109 int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter);
108 void AddFilter(Filter& filter); 110 void AddFilter(Filter& filter);
109 const Filters& GetFilters() const 111 const Filters& GetFilters() const
110 { 112 {
111 return mFilters; 113 return mFilters;
112 } 114 }
113 // behaves similar to virtual function 115 // behaves similar to virtual function
114 OwnedString SerializeProperties() const; 116 OwnedString SerializeProperties() const;
115 117
116 template<typename T> 118 template<typename T>
117 T* As(); 119 T* As()
120 {
121 if (mType != T::classType)
122 return nullptr;
123
124 return static_cast<T*>(this);
125 }
118 126
119 template<typename T> 127 template<typename T>
120 const T* As() const 128 const T* As() const
121 { 129 {
122 return const_cast<Subscription*>(this)->As<T>(); 130 if (mType != T::classType)
131 return nullptr;
132
133 return static_cast<const T*>(this);
123 } 134 }
135
124 protected: 136 protected:
125 OwnedString DoSerializeProperties() const; 137 OwnedString DoSerializeProperties() const;
Wladimir Palant 2017/12/21 10:30:38 Why is this method called DoSerializeProperties()
126 explicit Subscription(Type type, const String& id, const KeyValues& properties ); 138 explicit Subscription(Type type, const String& id, const KeyValues& properties );
127 static const String* findPropertyValue(const Subscription::KeyValues& properti es, const String& propertyName); 139 static const String* findPropertyValue(const Subscription::KeyValues& properti es, const String& propertyName);
128 template<typename Member> 140 template<typename Member>
129 static void parseProperty(const KeyValues& properties, Member& member, const S tring& key) 141 static void parseProperty(const KeyValues& properties, Member& member, const S tring& key)
130 { 142 {
131 if (auto strPropValue = findPropertyValue(properties, key)) 143 if (auto strPropValue = findPropertyValue(properties, key))
132 member = AdaptValue<Member>(*strPropValue); 144 member = lexical_cast<Member>(*strPropValue);
133 } 145 }
134 private: 146 private:
135 static SubscriptionPtr FromProperties(const String& id, const KeyValues& prope rties); 147 static SubscriptionPtr FromProperties(const String& id, const KeyValues& prope rties);
136 }; 148 };
149
150 ABP_NS_END
LEFTRIGHT

Powered by Google App Engine
This is Rietveld