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

Unified Diff: compiled/api.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Almost complete implementation, missing CSS property filters Created Jan. 20, 2016, 12:04 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/api.h ('k') | compiled/debug.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/api.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/api.cpp
@@ -0,0 +1,156 @@
+#include <exception>
+#include <string>
+
+#include <emscripten.h>
+
+#include "Filter.h"
+#include "InvalidFilter.h"
+#include "ActiveFilter.h"
+#include "RegExpFilter.h"
+#include "ElemHideBase.h"
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
+
+#define EXPOSE_FILTER_PROPERTY(class, type, getter, setter) \
+ type EMSCRIPTEN_KEEPALIVE class##_##getter(const FilterPtr& filter)\
+ {\
+ return std::dynamic_pointer_cast<class>(filter)->getter();\
+ }\
+ void EMSCRIPTEN_KEEPALIVE class##_##setter(\
+ const FilterPtr& filter, type value)\
+ {\
+ std::dynamic_pointer_cast<class>(filter)->setter(value);\
+ }
+
+extern "C"
+{
+ const char* EMSCRIPTEN_KEEPALIVE GetException(const std::exception& e)
+ {
+ return e.what();
+ }
+
+ size_t EMSCRIPTEN_KEEPALIVE GetSizeofString()
+ {
+ return sizeof(std::u16string);
+ }
+
+ void EMSCRIPTEN_KEEPALIVE InitString(std::u16string* str, char16_t* data, size_t len)
+ {
+ // String is already allocated on stack, we merely need to call constructor.
+ new (str) std::u16string(data, len);
+ }
+
+ void EMSCRIPTEN_KEEPALIVE DestroyString(std::u16string* str)
+ {
+ // Stack memory will be freed automatically, we need to call destructor
+ // explicitly however.
+ using namespace std;
+ str->~u16string();
+ }
+
+ size_t EMSCRIPTEN_KEEPALIVE GetStringLength(const std::u16string& str)
+ {
+ return str.length();
+ }
+
+ FilterPtr* EMSCRIPTEN_KEEPALIVE CreatePointer()
+ {
+ return new FilterPtr();
+ }
+
+ void EMSCRIPTEN_KEEPALIVE DeletePointer(FilterPtr* ptr)
+ {
+ delete ptr;
+ }
+
+ const char16_t* EMSCRIPTEN_KEEPALIVE GetStringData(const std::u16string& str)
+ {
+ return str.c_str();
+ }
+
+ std::u16string EMSCRIPTEN_KEEPALIVE Filter_GetText(const FilterPtr& filter)
+ {
+ return filter->GetText();
+ }
+
+ Filter::Type EMSCRIPTEN_KEEPALIVE Filter_GetType(const FilterPtr& filter)
+ {
+ return filter->GetType();
+ }
+
+ std::u16string EMSCRIPTEN_KEEPALIVE Filter_Serialize(const FilterPtr& filter)
+ {
+ return filter->Serialize();
+ }
+
+ FilterPtr EMSCRIPTEN_KEEPALIVE Filter_FromText(const std::u16string& text)
+ {
+ return Filter::FromText(text);
+ }
+
+ const std::u16string EMSCRIPTEN_KEEPALIVE Filter_Normalize(const std::u16string& text)
+ {
+ return Filter::Normalize(text);
+ }
+
+ const std::u16string EMSCRIPTEN_KEEPALIVE InvalidFilter_GetReason(const FilterPtr& filter)
+ {
+ return std::dynamic_pointer_cast<InvalidFilter>(filter)->GetReason();
+ }
+
+ EXPOSE_FILTER_PROPERTY(ActiveFilter, bool, GetDisabled, SetDisabled);
+ EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetHitCount, SetHitCount);
+ EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetLastHit, SetLastHit);
+
+ bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnDomain(
+ const FilterPtr& filter, const std::u16string& domain,
+ const std::u16string& sitekey)
+ {
+ return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsActiveOnDomain(
+ domain, sitekey
+ );
+ }
+
+ bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnlyOnDomain(
+ const FilterPtr& filter, const std::u16string& domain)
+ {
+ return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsActiveOnlyOnDomain(
+ domain
+ );
+ }
+
+ bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsGeneric(const FilterPtr& filter)
+ {
+ return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsGeneric();
+ }
+
+ void EMSCRIPTEN_KEEPALIVE RegExpFilter_InitJSTypes()
+ {
+ RegExpFilter::InitJSTypes();
+ }
+
+ bool EMSCRIPTEN_KEEPALIVE RegExpFilter_Matches(const FilterPtr& filter,
+ const std::u16string& location, int typeMask,
+ const std::u16string& docDomain, bool thirdParty,
+ const std::u16string& sitekey)
+ {
+ return std::dynamic_pointer_cast<RegExpFilter>(filter)->Matches(
+ location, typeMask, docDomain, thirdParty, sitekey
+ );
+ }
+
+ const std::u16string EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelector(
+ const FilterPtr& filter)
+ {
+ return std::dynamic_pointer_cast<ElemHideBase>(filter)->GetSelector();
+ }
+
+ const std::u16string EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelectorDomain(
+ const FilterPtr& filter)
+ {
+ return std::dynamic_pointer_cast<ElemHideBase>(filter)->GetSelectorDomain();
+ }
+}
+
+#pragma clang diagnostic pop
« no previous file with comments | « compiled/api.h ('k') | compiled/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld