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

Delta Between Two Patch Sets: compiled/filter/Filter.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/filter/ElemHideFilter.cpp ('k') | compiled/filter/Filter.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
23 #include "../String.h" 22 #include "../String.h"
24 #include "../intrusive_ptr.h" 23 #include "../intrusive_ptr.h"
25 #include "../debug.h" 24 #include "../debug.h"
26 #include "../bindings/runtime.h" 25 #include "../bindings/runtime.h"
27 26
28 class Filter : public ref_counted 27 class Filter : public ref_counted
29 { 28 {
30 protected: 29 protected:
(...skipping 22 matching lines...) Expand all
53 52
54 const String& BINDINGS_EXPORTED GetText() const 53 const String& BINDINGS_EXPORTED GetText() const
55 { 54 {
56 return mText; 55 return mText;
57 } 56 }
58 57
59 OwnedString BINDINGS_EXPORTED Serialize() const; 58 OwnedString BINDINGS_EXPORTED Serialize() const;
60 59
61 static Filter* BINDINGS_EXPORTED FromText(DependentString& text); 60 static Filter* BINDINGS_EXPORTED FromText(DependentString& text);
62 61
63 template<typename T, 62 template<typename T>
64 typename std::enable_if<std::is_base_of<Filter, T>::value>::type* = nullptr>
65 T* As() 63 T* As()
66 { 64 {
67 if ((mType & T::classType) != T::classType) 65 if ((mType & T::classType) != T::classType)
68 return nullptr; 66 return nullptr;
69 67
70 return static_cast<T*>(this); 68 return static_cast<T*>(this);
71 } 69 }
72 70
73 template<typename T, 71 template<typename T>
74 typename std::enable_if<std::is_base_of<Filter, T>::value>::type* = nullptr>
75 const T* As() const 72 const T* As() const
76 { 73 {
77 if ((mType & T::classType) != T::classType) 74 if ((mType & T::classType) != T::classType)
78 return nullptr; 75 return nullptr;
79 76
80 return static_cast<const T*>(this); 77 return static_cast<const T*>(this);
81 } 78 }
82 }; 79 };
83 80
84 typedef intrusive_ptr<Filter> FilterPtr; 81 typedef intrusive_ptr<Filter> FilterPtr;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld