Commit a362fd80 authored by Alexander Alekhin's avatar Alexander Alekhin

java: fix bindings generator

- fix imports override.
  Problem is observed with BoostDesc.

- add Ptr<> handling (constructor is protected from other packages).
  Observed in ximgproc:
      Ptr<StereoMatcher> createRightMatcher(Ptr<StereoMatcher> matcher_left)"
  where, "StereoMather" is from another package (calib3d)
parent 1237faef
...@@ -350,16 +350,22 @@ class JavaWrapperGenerator(object): ...@@ -350,16 +350,22 @@ class JavaWrapperGenerator(object):
if name in type_dict and not classinfo.base: if name in type_dict and not classinfo.base:
logging.warning('duplicated: %s', classinfo) logging.warning('duplicated: %s', classinfo)
return return
type_dict[name] = \ type_dict.setdefault(name, {}).update(
{ "j_type" : classinfo.jname, { "j_type" : classinfo.jname,
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
"jni_name" : "(*("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong", "jni_name" : "(*("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
"suffix" : "J" } "suffix" : "J",
type_dict[name+'*'] = \ "j_import" : "org.opencv.%s.%s" % (self.module, classinfo.jname)
}
)
type_dict.setdefault(name+'*', {}).update(
{ "j_type" : classinfo.jname, { "j_type" : classinfo.jname,
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
"jni_name" : "("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj", "jni_type" : "jlong", "jni_name" : "("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj", "jni_type" : "jlong",
"suffix" : "J" } "suffix" : "J",
"j_import" : "org.opencv.%s.%s" % (self.module, classinfo.jname)
}
)
# missing_consts { Module : { public : [[name, val],...], private : [[]...] } } # missing_consts { Module : { public : [[name, val],...], private : [[]...] } }
if name in missing_consts: if name in missing_consts:
...@@ -379,11 +385,14 @@ class JavaWrapperGenerator(object): ...@@ -379,11 +385,14 @@ class JavaWrapperGenerator(object):
if classinfo.base: if classinfo.base:
classinfo.addImports(classinfo.base) classinfo.addImports(classinfo.base)
type_dict["Ptr_"+name] = \ type_dict.setdefault("Ptr_"+name, {}).update(
{ "j_type" : classinfo.jname, { "j_type" : classinfo.jname,
"jn_type" : "long", "jn_args" : (("__int64", ".getNativeObjAddr()"),), "jn_type" : "long", "jn_args" : (("__int64", ".getNativeObjAddr()"),),
"jni_name" : "*((Ptr<"+classinfo.fullName(isCPP=True)+">*)%(n)s_nativeObj)", "jni_type" : "jlong", "jni_name" : "*((Ptr<"+classinfo.fullName(isCPP=True)+">*)%(n)s_nativeObj)", "jni_type" : "jlong",
"suffix" : "J" } "suffix" : "J",
"j_import" : "org.opencv.%s.%s" % (self.module, classinfo.jname)
}
)
logging.info('ok: class %s, name: %s, base: %s', classinfo, name, classinfo.base) logging.info('ok: class %s, name: %s, base: %s', classinfo, name, classinfo.base)
def add_const(self, decl): # [ "const cname", val, [], [] ] def add_const(self, decl): # [ "const cname", val, [], [] ]
...@@ -713,7 +722,7 @@ class JavaWrapperGenerator(object): ...@@ -713,7 +722,7 @@ class JavaWrapperGenerator(object):
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();') j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
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_"): elif ret_type.startswith("Ptr_"):
ret_val = type_dict[fi.ctype]["j_type"] + " retVal = new " + type_dict[ret_type]["j_type"] + "(" ret_val = type_dict[fi.ctype]["j_type"] + " retVal = " + type_dict[ret_type]["j_type"] + ".__fromPtr__("
tail = ")" tail = ")"
elif ret_type == "void": elif ret_type == "void":
ret_val = "" ret_val = ""
......
...@@ -13,3 +13,6 @@ public class $jname { ...@@ -13,3 +13,6 @@ public class $jname {
protected $jname(long addr) { nativeObj = addr; } protected $jname(long addr) { nativeObj = addr; }
public long getNativeObjAddr() { return nativeObj; } public long getNativeObjAddr() { return nativeObj; }
// internal usage only
public static $jname __fromPtr__(long addr) { return new $jname(addr); }
...@@ -10,3 +10,6 @@ $annotation ...@@ -10,3 +10,6 @@ $annotation
public class $jname extends $base { public class $jname extends $base {
protected $jname(long addr) { super(addr); } protected $jname(long addr) { super(addr); }
// internal usage only
public static $jname __fromPtr__(long addr) { return new $jname(addr); }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment