generate operator TYPE methods
MODIFY
gen_rust.py
gen_rust.py
@@ -19,7 +19,6 @@ from urllib.parse import quote
# fixme get multiline comments from LSD_REFINE_ADV in imgproc
# fixme add support for InputArray and friends to allow passing UMat
# fixme remove ndims argument when slice is supplied and read it from slice
-# fixme add support for geneating "operator TYPE" for doing type conversion, e.g. MatExpr to Mat (https://docs.opencv.org/4.1.1/d1/d10/classcv_1_1MatExpr.html#a14b681f8faccc92f32053ee037f22462)
def template(text):
"""
@@ -1035,6 +1034,7 @@ class ArgInfo:
class FuncInfo(GeneralInfo):
KIND_FUNCTION = "(function)"
KIND_METHOD = "(method)"
+ KIND_METHOD_CONVERT = "(convertor method)"
KIND_CONSTRUCTOR = "(constructor)"
TEMPLATES = {
@@ -1111,6 +1111,15 @@ class FuncInfo(GeneralInfo):
self.name = "new"
self.type = gen.get_type_info(self.classpath)
else:
+ operator_convert = False
+ m = re.match(r"operator\s+(\w+)$", self.name)
+ if m is not None:
+ out_type = gen.get_type_info(m.group(1))
+ if out_type is not None and not isinstance(out_type, UnknownTypeInfo):
+ operator_convert = True
+ self.kind = self.KIND_METHOD_CONVERT
+ self.type = out_type
+ if not operator_convert:
self.kind = self.KIND_METHOD
self.type = gen.get_type_info(decl[1])
else:
@@ -1118,7 +1127,7 @@ class FuncInfo(GeneralInfo):
self.ci = None # type: ClassInfo
self.type = gen.get_type_info(decl[1])
- self.identifier = self.fullname.replace("::", "_")
+ self.identifier = self.fullname.replace("::", "_").replace(" ", "_")
self.is_ignored = self.is_ignored or "/H" in decl[2] or "/I" in decl[2]
@@ -1164,7 +1173,7 @@ class FuncInfo(GeneralInfo):
logging.info("ignore destructor %s %s in %s"%(self.kind, self.name, self.ci))
self.is_ignored = True
- if self.name.startswith("operator") or self.fullname.startswith("operator "):
+ if (self.name.startswith("operator") or self.fullname.startswith("operator ")) and self.kind != self.KIND_METHOD_CONVERT:
logging.info("ignore %s %s in %s"%(self.kind, self.name, self.ci))
self.is_ignored = True
@@ -1207,7 +1216,7 @@ class FuncInfo(GeneralInfo):
if self.identifier in func_manual:
return None
- if self.name.startswith("operator"):
+ if self.name.startswith("operator") and self.kind != self.KIND_METHOD_CONVERT:
return "can not map %s yet"%(self.name)
if not self.rv_type():
@@ -1231,6 +1240,9 @@ class FuncInfo(GeneralInfo):
def r_name(self):
name = func_rename.get(self.identifier)
if name is None:
+ if self.kind == self.KIND_METHOD_CONVERT:
+ name = re.sub(r"^operator\s+", "to_", self.name)
+ else:
name = self.name
else:
if "+" in name:

MODIFY
src/manual/core/mat.rs
src/manual/core/mat.rs
@@ -7,7 +7,7 @@ use std::{
use libc::{c_uchar, size_t};
use crate::{
- core::{self, Mat, MatConstIterator, MatExpr, MatSize, MatStep, Scalar, UMat},
+ core::{self, Mat, MatConstIterator, MatSize, MatStep, Scalar, UMat},
Error,
Result,
sys,
@@ -553,19 +553,6 @@ impl MatConstIterator {
}
}
-impl MatExpr {
- pub fn to_mat(&self) -> Result<Mat> {
- let me = self.as_raw_MatExpr();
- cpp!(unsafe [me as "const MatExpr*"] -> sys::cv_return_value_const_void_X as "cv_return_value_void_X" {
- try {
- Mat ret = *me;
- return { Error::Code::StsOk, NULL, new Mat(ret) };
- } CVRS_CATCH(cv_return_value_void_X)
- }).into_result()
- .map(|ptr| core::Mat { ptr })
- }
-}
-
mod private {
pub trait Sealed {}
}

generate operator TYPE methods