Merge pull request #3180 from mshabunin:java_ptr_support
This commit is contained in:
commit
458bde5e24
@ -882,6 +882,11 @@ public class %(jc)s {
|
|||||||
self.add_class_code_stream(name, classinfo.base)
|
self.add_class_code_stream(name, classinfo.base)
|
||||||
if classinfo.base:
|
if classinfo.base:
|
||||||
self.get_imports(name, 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, [], [] ]
|
def add_const(self, decl): # [ "const cname", val, [], [] ]
|
||||||
@ -1256,6 +1261,9 @@ extern "C" {
|
|||||||
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
||||||
self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')
|
self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')
|
||||||
j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')
|
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":
|
elif ret_type == "void":
|
||||||
ret_val = ""
|
ret_val = ""
|
||||||
ret = "return;"
|
ret = "return;"
|
||||||
@ -1328,6 +1336,9 @@ extern "C" {
|
|||||||
default = 'return env->NewStringUTF("");'
|
default = 'return env->NewStringUTF("");'
|
||||||
elif fi.ctype in self.classes: # wrapped class:
|
elif fi.ctype in self.classes: # wrapped class:
|
||||||
ret = "return (jlong) new %s(_retval_);" % fi.ctype
|
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:
|
elif ret_type in self.classes: # pointer to wrapped class:
|
||||||
ret = "return (jlong) _retval_;"
|
ret = "return (jlong) _retval_;"
|
||||||
elif type_dict[fi.ctype]["jni_type"] == "jdoubleArray":
|
elif type_dict[fi.ctype]["jni_type"] == "jdoubleArray":
|
||||||
@ -1358,10 +1369,10 @@ extern "C" {
|
|||||||
elif fi.static:
|
elif fi.static:
|
||||||
cvname = "%s::%s" % (fi.classname, name)
|
cvname = "%s::%s" % (fi.classname, name)
|
||||||
else:
|
else:
|
||||||
cvname = "me->" + name
|
cvname = ("me->" if not self.isSmartClass(fi.classname) else "(*me)->") + name
|
||||||
c_prologue.append(\
|
c_prologue.append(\
|
||||||
"%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \
|
"%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \
|
||||||
% { "cls" : fi.classname} \
|
% { "cls" : self.smartWrap(fi.classname)} \
|
||||||
)
|
)
|
||||||
cvargs = []
|
cvargs = []
|
||||||
for a in args:
|
for a in args:
|
||||||
@ -1514,9 +1525,23 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
|
|||||||
delete (%(cls)s*) self;
|
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 __name__ == "__main__":
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 4:
|
||||||
|
Loading…
Reference in New Issue
Block a user