Added Ptr<T> support to Java wrappers
This commit is contained in:
parent
43c2c119e9
commit
66ed9ddbe3
@ -879,6 +879,11 @@ public class %(jc)s {
|
||||
self.add_class_code_stream(name, classinfo.base)
|
||||
if classinfo.base:
|
||||
self.get_imports(name, classinfo.base)
|
||||
type_dict["Ptr_"+name] = \
|
||||
{ "j_type" : name,
|
||||
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
||||
"jni_name" : "Ptr<"+name+">(("+name+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
|
||||
"suffix" : "J" }
|
||||
|
||||
|
||||
def add_const(self, decl): # [ "const cname", val, [], [] ]
|
||||
@ -1253,6 +1258,9 @@ extern "C" {
|
||||
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
||||
self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')
|
||||
j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')
|
||||
elif ret_type.startswith("Ptr_"):
|
||||
ret_val = type_dict[fi.ctype]["j_type"] + " retVal = new " + type_dict[ret_type]["j_type"] + "("
|
||||
tail = ")"
|
||||
elif ret_type == "void":
|
||||
ret_val = ""
|
||||
ret = "return;"
|
||||
@ -1325,6 +1333,9 @@ extern "C" {
|
||||
default = 'return env->NewStringUTF("");'
|
||||
elif fi.ctype in self.classes: # wrapped class:
|
||||
ret = "return (jlong) new %s(_retval_);" % fi.ctype
|
||||
elif fi.ctype.startswith('Ptr_'):
|
||||
c_prologue.append("typedef Ptr<%s> %s;" % (fi.ctype[4:], fi.ctype))
|
||||
ret = "return (jlong)(new %(ctype)s(_retval_));" % { 'ctype':fi.ctype }
|
||||
elif ret_type in self.classes: # pointer to wrapped class:
|
||||
ret = "return (jlong) _retval_;"
|
||||
elif type_dict[fi.ctype]["jni_type"] == "jdoubleArray":
|
||||
@ -1355,10 +1366,10 @@ extern "C" {
|
||||
elif fi.static:
|
||||
cvname = "%s::%s" % (fi.classname, name)
|
||||
else:
|
||||
cvname = "me->" + name
|
||||
cvname = ("me->" if not self.isSmartClass(fi.classname) else "(*me)->") + name
|
||||
c_prologue.append(\
|
||||
"%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \
|
||||
% { "cls" : fi.classname} \
|
||||
% { "cls" : self.smartWrap(fi.classname)} \
|
||||
)
|
||||
cvargs = []
|
||||
for a in args:
|
||||
@ -1511,9 +1522,23 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
|
||||
delete (%(cls)s*) self;
|
||||
}
|
||||
|
||||
""" % {"module" : module, "cls" : name, "j_cls" : ci.jname.replace('_', '_1')}
|
||||
""" % {"module" : module, "cls" : self.smartWrap(name), "j_cls" : ci.jname.replace('_', '_1')}
|
||||
)
|
||||
|
||||
def isSmartClass(self, classname):
|
||||
'''
|
||||
Check if class stores Ptr<T>* instead of T* in nativeObj field
|
||||
'''
|
||||
return classname in self.classes and self.classes[classname].base
|
||||
|
||||
def smartWrap(self, classname):
|
||||
'''
|
||||
Wraps class name with Ptr<> if needed
|
||||
'''
|
||||
if self.isSmartClass(classname):
|
||||
return "Ptr<" + classname + ">"
|
||||
return classname
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 4:
|
||||
|
Loading…
Reference in New Issue
Block a user