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

Side by Side Diff: compiled/api.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: How with CSS property filters Created Jan. 20, 2016, 1:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/api.h ('k') | compiled/debug.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <exception>
2 #include <string>
3
4 #include <emscripten.h>
5
6 #include "Filter.h"
7 #include "InvalidFilter.h"
8 #include "ActiveFilter.h"
9 #include "RegExpFilter.h"
10 #include "ElemHideBase.h"
11 #include "CSSPropertyFilter.h"
12
13 #pragma clang diagnostic push
14 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
15
16 #define EXPOSE_FILTER_PROPERTY(class, type, getter, setter) \
17 type EMSCRIPTEN_KEEPALIVE class##_##getter(const FilterPtr& filter)\
18 {\
19 return std::dynamic_pointer_cast<class>(filter)->getter();\
20 }\
21 void EMSCRIPTEN_KEEPALIVE class##_##setter(\
22 const FilterPtr& filter, type value)\
23 {\
24 std::dynamic_pointer_cast<class>(filter)->setter(value);\
25 }
26
27 extern "C"
28 {
29 const char* EMSCRIPTEN_KEEPALIVE GetException(const std::exception& e)
30 {
31 return e.what();
32 }
33
34 size_t EMSCRIPTEN_KEEPALIVE GetSizeofString()
35 {
36 return sizeof(std::u16string);
37 }
38
39 void EMSCRIPTEN_KEEPALIVE InitString(std::u16string* str, char16_t* data, size _t len)
40 {
41 // String is already allocated on stack, we merely need to call constructor.
42 new (str) std::u16string(data, len);
43 }
44
45 void EMSCRIPTEN_KEEPALIVE DestroyString(std::u16string* str)
46 {
47 // Stack memory will be freed automatically, we need to call destructor
48 // explicitly however.
49 using namespace std;
50 str->~u16string();
51 }
52
53 size_t EMSCRIPTEN_KEEPALIVE GetStringLength(const std::u16string& str)
54 {
55 return str.length();
56 }
57
58 FilterPtr* EMSCRIPTEN_KEEPALIVE CreatePointer()
59 {
60 return new FilterPtr();
61 }
62
63 void EMSCRIPTEN_KEEPALIVE DeletePointer(FilterPtr* ptr)
64 {
65 delete ptr;
66 }
67
68 const char16_t* EMSCRIPTEN_KEEPALIVE GetStringData(const std::u16string& str)
69 {
70 return str.c_str();
71 }
72
73 std::u16string EMSCRIPTEN_KEEPALIVE Filter_GetText(const FilterPtr& filter)
74 {
75 return filter->GetText();
76 }
77
78 Filter::Type EMSCRIPTEN_KEEPALIVE Filter_GetType(const FilterPtr& filter)
79 {
80 return filter->GetType();
81 }
82
83 std::u16string EMSCRIPTEN_KEEPALIVE Filter_Serialize(const FilterPtr& filter)
84 {
85 return filter->Serialize();
86 }
87
88 FilterPtr EMSCRIPTEN_KEEPALIVE Filter_FromText(const std::u16string& text)
89 {
90 return Filter::FromText(text);
91 }
92
93 const std::u16string EMSCRIPTEN_KEEPALIVE Filter_Normalize(const std::u16strin g& text)
94 {
95 return Filter::Normalize(text);
96 }
97
98 const std::u16string EMSCRIPTEN_KEEPALIVE InvalidFilter_GetReason(const Filter Ptr& filter)
99 {
100 return std::dynamic_pointer_cast<InvalidFilter>(filter)->GetReason();
101 }
102
103 EXPOSE_FILTER_PROPERTY(ActiveFilter, bool, GetDisabled, SetDisabled);
104 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetHitCount, SetHitCount);
105 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetLastHit, SetLastHit);
106
107 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnDomain(
108 const FilterPtr& filter, const std::u16string& domain,
109 const std::u16string& sitekey)
110 {
111 return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsActiveOnDomain(
112 domain, sitekey
113 );
114 }
115
116 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnlyOnDomain(
117 const FilterPtr& filter, const std::u16string& domain)
118 {
119 return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsActiveOnlyOnDomain (
120 domain
121 );
122 }
123
124 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsGeneric(const FilterPtr& filter)
125 {
126 return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsGeneric();
127 }
128
129 void EMSCRIPTEN_KEEPALIVE RegExpFilter_InitJSTypes()
130 {
131 RegExpFilter::InitJSTypes();
132 }
133
134 bool EMSCRIPTEN_KEEPALIVE RegExpFilter_Matches(const FilterPtr& filter,
135 const std::u16string& location, int typeMask,
136 const std::u16string& docDomain, bool thirdParty,
137 const std::u16string& sitekey)
138 {
139 return std::dynamic_pointer_cast<RegExpFilter>(filter)->Matches(
140 location, typeMask, docDomain, thirdParty, sitekey
141 );
142 }
143
144 const std::u16string EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelector(
145 const FilterPtr& filter)
146 {
147 return std::dynamic_pointer_cast<ElemHideBase>(filter)->GetSelector();
148 }
149
150 const std::u16string EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelectorDomain(
151 const FilterPtr& filter)
152 {
153 return std::dynamic_pointer_cast<ElemHideBase>(filter)->GetSelectorDomain();
154 }
155
156 const std::u16string EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetRegExpString(
157 const FilterPtr& filter)
158 {
159 return std::dynamic_pointer_cast<CSSPropertyFilter>(filter)->GetRegExpString ();
160 }
161
162 const std::u16string EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetSelectorPrefix(
163 const FilterPtr& filter)
164 {
165 return std::dynamic_pointer_cast<CSSPropertyFilter>(filter)->GetSelectorPref ix();
166 }
167
168 const std::u16string EMSCRIPTEN_KEEPALIVE CSSPropertyFilter_GetSelectorSuffix(
169 const FilterPtr& filter)
170 {
171 return std::dynamic_pointer_cast<CSSPropertyFilter>(filter)->GetSelectorSuff ix();
172 }
173 }
174
175 #pragma clang diagnostic pop
OLDNEW
« 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