Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/js/src/templates.py
16337 views
1
###############################################################################
2
#
3
# IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
#
5
# By downloading, copying, installing or using the software you agree to this license.
6
# If you do not agree to this license, do not download, install,
7
# copy or use the software.
8
#
9
#
10
# License Agreement
11
# For Open Source Computer Vision Library
12
#
13
# Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
# Third party copyrights are property of their respective owners.
15
#
16
# Redistribution and use in source and binary forms, with or without modification,
17
# are permitted provided that the following conditions are met:
18
#
19
# * Redistribution's of source code must retain the above copyright notice,
20
# this list of conditions and the following disclaimer.
21
#
22
# * Redistribution's in binary form must reproduce the above copyright notice,
23
# this list of conditions and the following disclaimer in the documentation
24
# and/or other materials provided with the distribution.
25
#
26
# * The name of the copyright holders may not be used to endorse or promote products
27
# derived from this software without specific prior written permission.
28
#
29
# This software is provided by the copyright holders and contributors "as is" and
30
# any express or implied warranties, including, but not limited to, the implied
31
# warranties of merchantability and fitness for a particular purpose are disclaimed.
32
# In no event shall the Intel Corporation or contributors be liable for any direct,
33
# indirect, incidental, special, exemplary, or consequential damages
34
# (including, but not limited to, procurement of substitute goods or services;
35
# loss of use, data, or profits; or business interruption) however caused
36
# and on any theory of liability, whether in contract, strict liability,
37
# or tort (including negligence or otherwise) arising in any way out of
38
# the use of this software, even if advised of the possibility of such damage.
39
#
40
41
###############################################################################
42
# AUTHOR: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
43
#
44
# LICENSE AGREEMENT
45
# Copyright (c) 2015, 2015 The Regents of the University of California (Regents)
46
#
47
# Redistribution and use in source and binary forms, with or without
48
# modification, are permitted provided that the following conditions are met:
49
# 1. Redistributions of source code must retain the above copyright
50
# notice, this list of conditions and the following disclaimer.
51
# 2. Redistributions in binary form must reproduce the above copyright
52
# notice, this list of conditions and the following disclaimer in the
53
# documentation and/or other materials provided with the distribution.
54
# 3. Neither the name of the University nor the
55
# names of its contributors may be used to endorse or promote products
56
# derived from this software without specific prior written permission.
57
#
58
# THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
59
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61
# DISCLAIMED. IN NO EVENT SHALL COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
62
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
63
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
65
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
67
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68
##############################################################################
69
70
from string import Template
71
72
wrapper_codes_template = Template("namespace $ns {\n$defs\n}")
73
74
call_template = Template("""$func($args)""")
75
class_call_template = Template("""$obj.$func($args)""")
76
static_class_call_template = Template("""$scope$func($args)""")
77
78
wrapper_function_template = Template(""" $ret_val $func($signature)$const {
79
return $cpp_call;
80
}
81
""")
82
83
wrapper_function_with_def_args_template = Template(""" $ret_val $func($signature)$const {
84
$check_args
85
}
86
""")
87
88
wrapper_overload_def_values = [
89
Template("""return $cpp_call;"""), Template("""if ($arg0.isUndefined())
90
return $cpp_call;
91
else
92
$next"""),
93
Template("""if ($arg0.isUndefined() && $arg1.isUndefined())
94
return $cpp_call;
95
else $next"""),
96
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined())
97
return $cpp_call;
98
else $next"""),
99
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined())
100
return $cpp_call;
101
else $next"""),
102
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
103
$arg4.isUndefined())
104
return $cpp_call;
105
else $next"""),
106
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
107
$arg4.isUndefined() && $arg5.isUndefined() )
108
return $cpp_call;
109
else $next"""),
110
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
111
$arg4.isUndefined() && $arg5.isUndefined() && $arg6.isUndefined() )
112
return $cpp_call;
113
else $next"""),
114
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
115
$arg4.isUndefined() && $arg5.isUndefined()&& $arg6.isUndefined() && $arg7.isUndefined())
116
return $cpp_call;
117
else $next"""),
118
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
119
$arg4.isUndefined() && $arg5.isUndefined()&& $arg6.isUndefined() && $arg7.isUndefined() &&
120
$arg8.isUndefined())
121
return $cpp_call;
122
else $next"""),
123
Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
124
$arg4.isUndefined() && $arg5.isUndefined()&& $arg6.isUndefined() && $arg7.isUndefined()&&
125
$arg8.isUndefined() && $arg9.isUndefined())
126
return $cpp_call;
127
else $next""")]
128
129
emscripten_binding_template = Template("""
130
131
EMSCRIPTEN_BINDINGS($binding_name) {$bindings
132
}
133
""")
134
135
simple_function_template = Template("""
136
emscripten::function("$js_name", &$cpp_name);
137
""")
138
139
smart_ptr_reg_template = Template("""
140
.smart_ptr<Ptr<$cname>>("Ptr<$name>")
141
""")
142
143
overload_function_template = Template("""
144
function("$js_name", select_overload<$ret($args)$const>(&$cpp_name)$optional);
145
""")
146
147
overload_class_function_template = Template("""
148
.function("$js_name", select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
149
150
overload_class_static_function_template = Template("""
151
.class_function("$js_name", select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
152
153
class_property_template = Template("""
154
.property("$js_name", &$cpp_name)""")
155
156
class_property_enum_template = Template("""
157
.property("$js_name", binding_utils::underlying_ptr(&$cpp_name))""")
158
159
ctr_template = Template("""
160
.constructor(select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
161
162
smart_ptr_ctr_overload_template = Template("""
163
.smart_ptr_constructor("$ptr_type", select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
164
165
function_template = Template("""
166
.function("$js_name", &$cpp_name)""")
167
168
static_function_template = Template("""
169
.class_function("$js_name", &$cpp_name)""")
170
171
constructor_template = Template("""
172
.constructor<$signature>()""")
173
174
enum_item_template = Template("""
175
.value("$val", $cpp_val)""")
176
177
enum_template = Template("""
178
emscripten::enum_<$cpp_name>("$js_name")$enum_items;
179
""")
180
181
const_template = Template("""
182
constant("$js_name", static_cast<long>($value));
183
""")
184
185
vector_template = Template("""
186
emscripten::register_vector<$cType>("$js_name");
187
""")
188
189
map_template = Template("""
190
emscripten::register_map<cpp_type_key,$cpp_type_val>("$js_name");
191
""")
192
193
class_template = Template("""
194
emscripten::class_<$cpp_name $derivation>("$js_name")$class_templates;
195
""")
196
197