Index: compiled/filter/Filter.h |
=================================================================== |
--- a/compiled/filter/Filter.h |
+++ b/compiled/filter/Filter.h |
@@ -12,16 +12,17 @@ |
* 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 "../String.h" |
#include "../intrusive_ptr.h" |
#include "../debug.h" |
#include "../bindings/runtime.h" |
class Filter : public ref_counted |
@@ -30,32 +31,54 @@ protected: |
OwnedString mText; |
public: |
enum Type |
{ |
UNKNOWN = 0, |
INVALID = 1, |
COMMENT = 2, |
- BLOCKING = 3, |
- WHITELIST = 4, |
- ELEMHIDE = 5, |
- ELEMHIDEEXCEPTION = 6, |
- ELEMHIDEEMULATION = 7, |
- VALUE_COUNT = 8 |
+ ACTIVE = 4, |
+ REGEXP = ACTIVE | 8, |
+ BLOCKING = REGEXP | 16, |
+ WHITELIST = REGEXP | 32, |
+ ELEMHIDEBASE = ACTIVE | 64, |
+ ELEMHIDE = ELEMHIDEBASE | 128, |
+ ELEMHIDEEXCEPTION = ELEMHIDEBASE | 256, |
+ ELEMHIDEEMULATION = ELEMHIDEBASE | 512 |
}; |
explicit Filter(Type type, const String& text); |
~Filter(); |
Type mType; |
const String& BINDINGS_EXPORTED GetText() const |
{ |
return mText; |
} |
OwnedString BINDINGS_EXPORTED Serialize() const; |
static Filter* BINDINGS_EXPORTED FromText(DependentString& text); |
+ |
+ template<typename T, |
+ typename std::enable_if<std::is_base_of<Filter, T>::value>::type* = nullptr> |
+ T* As() |
+ { |
+ if ((mType & T::classType) != T::classType) |
+ return nullptr; |
+ |
+ return static_cast<T*>(this); |
+ } |
+ |
+ template<typename T, |
+ typename std::enable_if<std::is_base_of<Filter, T>::value>::type* = nullptr> |
+ const T* As() const |
+ { |
+ if ((mType & T::classType) != T::classType) |
+ return nullptr; |
+ |
+ return static_cast<const T*>(this); |
+ } |
}; |
typedef intrusive_ptr<Filter> FilterPtr; |