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: Back to manual approach for API Created Jan. 18, 2016, 12:41 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/shell.js » ('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
11 #pragma clang diagnostic push
12 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
13
14 #define EXPOSE_FILTER_PROPERTY(class, type, getter, setter) \
15 type EMSCRIPTEN_KEEPALIVE class##_##getter(const FilterPtr& filter)\
16 {\
17 return std::dynamic_pointer_cast<class>(filter)->getter();\
18 }\
19 void EMSCRIPTEN_KEEPALIVE class##_##setter(\
20 const FilterPtr& filter, type value)\
21 {\
22 std::dynamic_pointer_cast<class>(filter)->setter(value);\
23 }
24
25 extern "C"
26 {
27 const char* EMSCRIPTEN_KEEPALIVE GetException(const std::exception& e)
28 {
29 return e.what();
30 }
31
32 size_t EMSCRIPTEN_KEEPALIVE GetSizeofString()
33 {
34 return sizeof(std::u16string);
35 }
36
37 void EMSCRIPTEN_KEEPALIVE InitString(std::u16string* str, char16_t* data, size _t len)
38 {
39 // String is already allocated on stack, we merely need to call constructor.
40 new (str) std::u16string(data, len);
41 }
42
43 void EMSCRIPTEN_KEEPALIVE DestroyString(std::u16string* str)
44 {
45 // Stack memory will be freed automatically, we need to call destructor
46 // explicitly however.
47 using namespace std;
48 str->~u16string();
49 }
50
51 size_t EMSCRIPTEN_KEEPALIVE GetStringLength(const std::u16string& str)
52 {
53 return str.length();
54 }
55
56 FilterPtr* EMSCRIPTEN_KEEPALIVE CreatePointer()
57 {
58 return new FilterPtr();
59 }
60
61 void EMSCRIPTEN_KEEPALIVE DeletePointer(FilterPtr* ptr)
62 {
63 delete ptr;
64 }
65
66 const char16_t* EMSCRIPTEN_KEEPALIVE GetStringData(const std::u16string& str)
67 {
68 return str.c_str();
69 }
70
71 std::u16string EMSCRIPTEN_KEEPALIVE Filter_GetText(const FilterPtr& filter)
72 {
73 return filter->GetText();
74 }
75
76 Filter::Type EMSCRIPTEN_KEEPALIVE Filter_GetType(const FilterPtr& filter)
77 {
78 return filter->GetType();
79 }
80
81 FilterPtr EMSCRIPTEN_KEEPALIVE Filter_FromText(const std::u16string& text)
82 {
83 return Filter::FromText(text);
84 }
85
86 const std::u16string EMSCRIPTEN_KEEPALIVE Filter_Normalize(const std::u16strin g& text)
87 {
88 return Filter::Normalize(text);
89 }
90
91 const std::u16string EMSCRIPTEN_KEEPALIVE InvalidFilter_GetReason(const Filter Ptr& filter)
92 {
93 return std::dynamic_pointer_cast<InvalidFilter>(filter)->GetReason();
94 }
95
96 EXPOSE_FILTER_PROPERTY(ActiveFilter, bool, GetDisabled, SetDisabled);
97 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetHitCount, SetHitCount);
98 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetLastHit, SetLastHit);
99
100 bool EMSCRIPTEN_KEEPALIVE RegExpFilter_Matches(const FilterPtr& filter, const std::u16string& location)
101 {
102 return std::dynamic_pointer_cast<RegExpFilter>(filter)->Matches(location);
103 }
104 }
105
106 #pragma clang diagnostic pop
OLDNEW
« no previous file with comments | « compiled/api.h ('k') | compiled/shell.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld