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

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

Issue 29574591: Issue 5258 - Implement Filter::As<>() method to make working with filters easier from C++ code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Use static classType member Created Oct. 13, 2017, 11:40 a.m.
Right Patch Set: Removed unnecessary base class check Created Oct. 13, 2017, 4:57 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/UserDefinedSubscription.h » ('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
23 #include "../filter/Filter.h" 22 #include "../filter/Filter.h"
24 #include "../String.h" 23 #include "../String.h"
25 #include "../FilterNotifier.h" 24 #include "../FilterNotifier.h"
26 #include "../intrusive_ptr.h" 25 #include "../intrusive_ptr.h"
27 #include "../debug.h" 26 #include "../debug.h"
28 #include "../bindings/runtime.h" 27 #include "../bindings/runtime.h"
29 28
30 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett er, setter) \ 29 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett er, setter) \
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return mFilters.size(); 91 return mFilters.size();
93 } 92 }
94 93
95 Filter* BINDINGS_EXPORTED FilterAt(Filters::size_type index); 94 Filter* BINDINGS_EXPORTED FilterAt(Filters::size_type index);
96 int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter); 95 int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter);
97 OwnedString BINDINGS_EXPORTED Serialize() const; 96 OwnedString BINDINGS_EXPORTED Serialize() const;
98 OwnedString BINDINGS_EXPORTED SerializeFilters() const; 97 OwnedString BINDINGS_EXPORTED SerializeFilters() const;
99 98
100 static Subscription* BINDINGS_EXPORTED FromID(const String& id); 99 static Subscription* BINDINGS_EXPORTED FromID(const String& id);
101 100
102 template<typename T, 101 template<typename T>
103 typename std::enable_if<std::is_base_of<Subscription, T>::value>::type* = nu llptr>
sergei 2017/10/13 12:34:36 static_cast does not allow down casting at a compi
Wladimir Palant 2017/10/13 16:58:18 You are correct, removed.
104 T* As() 102 T* As()
105 { 103 {
106 if (mType != T::classType) 104 if (mType != T::classType)
107 return nullptr; 105 return nullptr;
108 106
109 return static_cast<T*>(this); 107 return static_cast<T*>(this);
sergei 2017/10/13 12:34:36 In addition, since T::classType seems already a co
Wladimir Palant 2017/10/13 16:58:18 Note that we have different checks for Filter and
110 } 108 }
111 109
112 template<typename T, 110 template<typename T>
113 typename std::enable_if<std::is_base_of<Subscription, T>::value>::type* = nu llptr>
114 const T* As() const 111 const T* As() const
115 { 112 {
116 if (mType != T::classType) 113 if (mType != T::classType)
117 return nullptr; 114 return nullptr;
118 115
119 return static_cast<const T*>(this); 116 return static_cast<const T*>(this);
120 } 117 }
121 }; 118 };
122 119
123 typedef intrusive_ptr<Subscription> SubscriptionPtr; 120 typedef intrusive_ptr<Subscription> SubscriptionPtr;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld