JS: Support enum properties

This commit is contained in:
Hamdi Sahloul 2018-09-23 23:36:42 +09:00
parent 475c775b25
commit 0739d1c2eb
3 changed files with 11 additions and 1 deletions

View File

@ -78,6 +78,12 @@ using namespace dnn;
namespace binding_utils namespace binding_utils
{ {
template<typename classT, typename enumT>
static inline typename std::underlying_type<enumT>::type classT::* underlying_ptr(enumT classT::* enum_ptr)
{
return reinterpret_cast<typename std::underlying_type<enumT>::type classT::*>(enum_ptr);
}
template<typename T> template<typename T>
emscripten::val matData(const cv::Mat& mat) emscripten::val matData(const cv::Mat& mat)
{ {

View File

@ -856,7 +856,8 @@ class JSWrapperGenerator(object):
# Generate bindings for properties # Generate bindings for properties
for property in class_info.props: 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]))) [class_info.cname, property.name])))
dv = '' dv = ''

View File

@ -153,6 +153,9 @@ overload_class_static_function_template = Template("""
class_property_template = Template(""" class_property_template = Template("""
.property("$js_name", &$cpp_name)""") .property("$js_name", &$cpp_name)""")
class_property_enum_template = Template("""
.property("$js_name", binding_utils::underlying_ptr(&$cpp_name))""")
ctr_template = Template(""" ctr_template = Template("""
.constructor(select_overload<$ret($args)$const>(&$cpp_name)$optional)""") .constructor(select_overload<$ret($args)$const>(&$cpp_name)$optional)""")