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: Use static classType member Created Oct. 13, 2017, 11:40 a.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
@@ -94,13 +94,30 @@ 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();
+ template<typename T,
+ typename std::enable_if<std::is_base_of<Subscription, T>::value>::type* = nullptr>
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.
+ T* As()
+ {
+ if (mType != T::classType)
+ return nullptr;
+
+ 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
+ }
+
+ template<typename T,
+ typename std::enable_if<std::is_base_of<Subscription, T>::value>::type* = nullptr>
+ 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