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

Unified 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: Removed unnecessary base class check Created Oct. 13, 2017, 4:57 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/UserDefinedSubscription.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/subscription/Subscription.h
===================================================================
--- a/compiled/subscription/Subscription.h
+++ b/compiled/subscription/Subscription.h
@@ -12,17 +12,16 @@
* 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 "../FilterNotifier.h"
#include "../intrusive_ptr.h"
#include "../debug.h"
#include "../bindings/runtime.h"
@@ -95,12 +94,27 @@ public:
Filter* BINDINGS_EXPORTED FilterAt(Filters::size_type index);
int BINDINGS_EXPORTED IndexOfFilter(const Filter& filter);
OwnedString BINDINGS_EXPORTED Serialize() const;
OwnedString BINDINGS_EXPORTED SerializeFilters() const;
static Subscription* BINDINGS_EXPORTED FromID(const String& id);
template<typename T>
- T* As();
+ T* As()
+ {
+ if (mType != T::classType)
+ return nullptr;
+
+ return static_cast<T*>(this);
+ }
+
+ template<typename T>
+ const T* As() const
+ {
+ if (mType != T::classType)
+ return nullptr;
+
+ return static_cast<const T*>(this);
+ }
};
typedef intrusive_ptr<Subscription> SubscriptionPtr;
« 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