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

Side by Side Diff: 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
Patch Set: Use static classType member Created Oct. 13, 2017, 11:40 a.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
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
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return mFilters.size(); 92 return mFilters.size();
93 } 93 }
94 94
95 Filter* BINDINGS_EXPORTED FilterAt(Filters::size_type index); 95 Filter* BINDINGS_EXPORTED FilterAt(Filters::size_type index);
96 int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter); 96 int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter);
97 OwnedString BINDINGS_EXPORTED Serialize() const; 97 OwnedString BINDINGS_EXPORTED Serialize() const;
98 OwnedString BINDINGS_EXPORTED SerializeFilters() const; 98 OwnedString BINDINGS_EXPORTED SerializeFilters() const;
99 99
100 static Subscription* BINDINGS_EXPORTED FromID(const String& id); 100 static Subscription* BINDINGS_EXPORTED FromID(const String& id);
101 101
102 template<typename T> 102 template<typename T,
103 T* As(); 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()
105 {
106 if (mType != T::classType)
107 return nullptr;
108
109 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 }
111
112 template<typename T,
113 typename std::enable_if<std::is_base_of<Subscription, T>::value>::type* = nu llptr>
114 const T* As() const
115 {
116 if (mType != T::classType)
117 return nullptr;
118
119 return static_cast<const T*>(this);
120 }
104 }; 121 };
105 122
106 typedef intrusive_ptr<Subscription> SubscriptionPtr; 123 typedef intrusive_ptr<Subscription> SubscriptionPtr;
OLDNEW
« no previous file with comments | « compiled/subscription/DownloadableSubscription.cpp ('k') | compiled/subscription/UserDefinedSubscription.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld