1 ###############################################################################
3 # IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 # For Open Source Computer Vision Library
13 # Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14 # Third party copyrights are property of their respective owners.
16 # Redistribution and use in source and binary forms, with or without modification,
17 # are permitted provided that the following conditions are met:
19 # * Redistribution's of source code must retain the above copyright notice,
20 # this list of conditions and the following disclaimer.
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.
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.
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.
41 ###############################################################################
42 # AUTHOR: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
45 # Copyright (c) 2015, 2015 The Regents of the University of California (Regents)
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.
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 ##############################################################################
70 from string import Template
72 wrapper_codes_template = Template("namespace $ns {\n$defs\n}")
74 call_template = Template("""$func($args)""")
75 class_call_template = Template("""$obj.$func($args)""")
76 static_class_call_template = Template("""$scope$func($args)""")
78 wrapper_function_template = Template(""" $ret_val $func($signature)$const {
83 wrapper_function_with_def_args_template = Template(""" $ret_val $func($signature)$const {
88 wrapper_overload_def_values = [
89 Template("""return $cpp_call;"""), Template("""if ($arg0.isUndefined())
93 Template("""if ($arg0.isUndefined() && $arg1.isUndefined())
96 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined())
99 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined())
102 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
106 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
107 $arg4.isUndefined() && $arg5.isUndefined() )
110 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
111 $arg4.isUndefined() && $arg5.isUndefined() && $arg6.isUndefined() )
114 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
115 $arg4.isUndefined() && $arg5.isUndefined()&& $arg6.isUndefined() && $arg7.isUndefined())
118 Template("""if ($arg0.isUndefined() && $arg1.isUndefined() && $arg2.isUndefined() && $arg3.isUndefined() &&
119 $arg4.isUndefined() && $arg5.isUndefined()&& $arg6.isUndefined() && $arg7.isUndefined() &&
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())
129 emscripten_binding_template = Template("""
131 EMSCRIPTEN_BINDINGS($binding_name) {$bindings
135 simple_function_template = Template("""
136 emscripten::function("$js_name", &$cpp_name);
139 smart_ptr_reg_template = Template("""
140 .smart_ptr<Ptr<$cname>>("Ptr<$name>")
143 overload_function_template = Template("""
144 function("$js_name", select_overload<$ret($args)$const>(&$cpp_name)$optional);
147 overload_class_function_template = Template("""
148 .function("$js_name", select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
150 overload_class_static_function_template = Template("""
151 .class_function("$js_name", select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
153 class_property_template = Template("""
154 .property("$js_name", &$cpp_name)""")
156 class_property_enum_template = Template("""
157 .property("$js_name", binding_utils::underlying_ptr(&$cpp_name))""")
159 ctr_template = Template("""
160 .constructor(select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
162 smart_ptr_ctr_overload_template = Template("""
163 .smart_ptr_constructor("$ptr_type", select_overload<$ret($args)$const>(&$cpp_name)$optional)""")
165 function_template = Template("""
166 .function("$js_name", &$cpp_name)""")
168 static_function_template = Template("""
169 .class_function("$js_name", &$cpp_name)""")
171 constructor_template = Template("""
172 .constructor<$signature>()""")
174 enum_item_template = Template("""
175 .value("$val", $cpp_val)""")
177 enum_template = Template("""
178 emscripten::enum_<$cpp_name>("$js_name")$enum_items;
181 const_template = Template("""
182 constant("$js_name", static_cast<long>($value));
185 vector_template = Template("""
186 emscripten::register_vector<$cType>("$js_name");
189 map_template = Template("""
190 emscripten::register_map<cpp_type_key,$cpp_type_val>("$js_name");
193 class_template = Template("""
194 emscripten::class_<$cpp_name $derivation>("$js_name")$class_templates;