1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Adding of user-defined type conversions for python bindings inside module directories

Adding of destructor and placement new constructors for classes wrapped with CV_EXPORTS_W_SIMPLE macro
This commit is contained in:
Vitaliy Lyudvichenko
2016-08-06 19:46:17 +03:00
parent 35d0a45df6
commit ab8de8f506
8 changed files with 132 additions and 136 deletions
+5 -3
View File
@@ -30,7 +30,7 @@ gen_template_call_constructor = Template("""self->v.reset(new ${cname}${args})""
gen_template_simple_call_constructor_prelude = Template("""self = PyObject_NEW(pyopencv_${name}_t, &pyopencv_${name}_Type);
if(self) """)
gen_template_simple_call_constructor = Template("""self->v = ${cname}${args}""")
gen_template_simple_call_constructor = Template("""new (&(self->v)) ${cname}${args}""")
gen_template_parse_args = Template("""const char* keywords[] = { $kw_list, NULL };
if( PyArg_ParseTupleAndKeywords(args, kw, "$fmtspec", (char**)keywords, $parse_arglist)$code_cvt )""")
@@ -74,13 +74,14 @@ static PyTypeObject pyopencv_${name}_Type =
static void pyopencv_${name}_dealloc(PyObject* self)
{
((pyopencv_${name}_t*)self)->v.${cname}::~${sname}();
PyObject_Del(self);
}
template<> PyObject* pyopencv_from(const ${cname}& r)
{
pyopencv_${name}_t *m = PyObject_NEW(pyopencv_${name}_t, &pyopencv_${name}_Type);
m->v = r;
new (&m->v) ${cname}(r); //Copy constructor
return (PyObject*)m;
}
@@ -258,6 +259,7 @@ class ClassInfo(object):
def __init__(self, name, decl=None):
self.cname = name.replace(".", "::")
self.name = self.wname = normalize_class_name(name)
self.sname = name[name.rfind('.') + 1:]
self.ismap = False
self.issimple = False
self.isalgorithm = False
@@ -904,7 +906,7 @@ class PythonWrapperGenerator(object):
templ = gen_template_simple_type_decl
else:
templ = gen_template_type_decl
self.code_types.write(templ.substitute(name=name, wname=classinfo.wname, cname=classinfo.cname,
self.code_types.write(templ.substitute(name=name, wname=classinfo.wname, cname=classinfo.cname, sname=classinfo.sname,
cname1=("cv::Algorithm" if classinfo.isalgorithm else classinfo.cname)))
# register classes in the same order as they have been declared.