From 0739d1c2eb9e508139ab3d2c8da8a5a893b86e1f Mon Sep 17 00:00:00 2001 From: Hamdi Sahloul Date: Sun, 23 Sep 2018 23:36:42 +0900 Subject: [PATCH] JS: Support enum properties --- modules/js/src/core_bindings.cpp | 6 ++++++ modules/js/src/embindgen.py | 3 ++- modules/js/src/templates.py | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/js/src/core_bindings.cpp b/modules/js/src/core_bindings.cpp index e8f0ee7f85..8e6bff928e 100644 --- a/modules/js/src/core_bindings.cpp +++ b/modules/js/src/core_bindings.cpp @@ -78,6 +78,12 @@ using namespace dnn; namespace binding_utils { + template + static inline typename std::underlying_type::type classT::* underlying_ptr(enumT classT::* enum_ptr) + { + return reinterpret_cast::type classT::*>(enum_ptr); + } + template emscripten::val matData(const cv::Mat& mat) { diff --git a/modules/js/src/embindgen.py b/modules/js/src/embindgen.py index 9f736b90d1..5865049595 100644 --- a/modules/js/src/embindgen.py +++ b/modules/js/src/embindgen.py @@ -856,7 +856,8 @@ class JSWrapperGenerator(object): # Generate bindings for properties for property in class_info.props: - class_bindings.append(class_property_template.substitute(js_name=property.name, cpp_name='::'.join( + _class_property = class_property_enum_template if property.tp in type_dict else class_property_template + class_bindings.append(_class_property.substitute(js_name=property.name, cpp_name='::'.join( [class_info.cname, property.name]))) dv = '' diff --git a/modules/js/src/templates.py b/modules/js/src/templates.py index be9d61ef14..76e383cfac 100644 --- a/modules/js/src/templates.py +++ b/modules/js/src/templates.py @@ -153,6 +153,9 @@ overload_class_static_function_template = Template(""" class_property_template = Template(""" .property("$js_name", &$cpp_name)""") +class_property_enum_template = Template(""" + .property("$js_name", binding_utils::underlying_ptr(&$cpp_name))""") + ctr_template = Template(""" .constructor(select_overload<$ret($args)$const>(&$cpp_name)$optional)""")