| Index: compiled/api.cpp |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/compiled/api.cpp |
| @@ -0,0 +1,106 @@ |
| +#include <exception> |
| +#include <string> |
| + |
| +#include <emscripten.h> |
| + |
| +#include "Filter.h" |
| +#include "InvalidFilter.h" |
| +#include "ActiveFilter.h" |
| +#include "RegExpFilter.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(); |
| + } |
| + |
| + 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 RegExpFilter_Matches(const FilterPtr& filter, const std::u16string& location) |
| + { |
| + return std::dynamic_pointer_cast<RegExpFilter>(filter)->Matches(location); |
| + } |
| +} |
| + |
| +#pragma clang diagnostic pop |