Add generation for increment and decrement operators
MODIFY
binding-generator/src/func.rs
binding-generator/src/func.rs
@@ -41,6 +41,8 @@ pub enum OperatorKind {
Div,
Deref,
Equals,
+ Incr,
+ Decr,
}
impl OperatorKind {
@@ -68,6 +70,12 @@ impl OperatorKind {
"==" => {
OperatorKind::Equals
}
+ "++" => {
+ OperatorKind::Incr
+ }
+ "--" => {
+ OperatorKind::Decr
+ }
_ => {
OperatorKind::Unsupported
},
@@ -290,13 +298,13 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
}
}
- pub fn as_operator(&self) -> Option<(Option<Class<'tu, 'ge>>, OperatorKind)> {
+ pub fn as_operator(&self) -> Option<OperatorKind> {
match self.kind() {
Kind::FunctionOperator(kind) => {
- Some((None, kind))
+ Some(kind)
}
- Kind::InstanceOperator(cls, kind) => {
- Some((Some(cls), kind))
+ Kind::InstanceOperator(_, kind) => {
+ Some(kind)
}
_ => {
None
@@ -557,6 +565,14 @@ impl Element for Func<'_, '_> {
}
DefaultElement::is_excluded(self)
|| self.is_generic()
+ || self.as_operator().map_or(false, |kind| {
+ if matches!(kind, OperatorKind::Incr | OperatorKind::Decr) {
+ // filter out postfix version of ++ and --: https://en.cppreference.com/w/cpp/language/operator_incdec
+ self.clang_arguments().len() == 1
+ } else {
+ false
+ }
+ })
|| if let Some(cls) = self.as_constructor() { // don't generate constructors of abstract classes
cls.is_abstract()
} else {
@@ -571,7 +587,7 @@ impl Element for Func<'_, '_> {
}
DefaultElement::is_ignored(self)
|| self.entity.get_availability() == Availability::Unavailable
- || self.as_operator().map_or(false, |(.., op)| op == OperatorKind::Unsupported)
+ || self.as_operator().map_or(false, |op| op == OperatorKind::Unsupported)
|| self.arguments().into_iter().any(|a| a.type_ref().is_ignored())
|| {
let ret = self.return_type();
@@ -691,7 +707,7 @@ impl Element for Func<'_, '_> {
let mut name: String = self.return_type().rust_local().into_owned();
name.cleanup_name();
format!("to_{}", name).into()
- } else if let Some((.., kind)) = self.as_operator() {
+ } else if let Some(kind) = self.as_operator() {
if cpp_name.starts_with("operator") {
match kind {
OperatorKind::Unsupported => {
@@ -726,6 +742,13 @@ impl Element for Func<'_, '_> {
OperatorKind::Equals => {
"equals".into()
}
+
+ OperatorKind::Incr => {
+ "incr".into()
+ }
+ OperatorKind::Decr => {
+ "decr".into()
+ }
}
} else {
cpp_name

MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -565,6 +565,9 @@ pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| hashmap! {
});
pub static FUNC_CFG_ATTR: Lazy<HashMap<&str, (&str, &str)>> = Lazy::new(|| hashmap! {
+ // ### core ###
+ "cv_SparseMatConstIterator_operatorSS" => ("not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"),
+
// ### imgproc ###
"cv_getRotationMatrix2D__Point2f_double_double" => ("not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"),

MODIFY
tests/imgproc.rs
tests/imgproc.rs
#![cfg(ocvrs_has_module_imgproc)]
use opencv::{
- core::{Point, Point2f, Scalar, Size, Vec2f},
+ core::{Point, Point2f, Scalar, Size, Vec2f, Mat_AUTO_STEP},
imgproc,
prelude::*,
Result,
@@ -41,3 +41,25 @@ fn get_rotation_matrix_2d() -> Result<()> {
assert_eq!(-*mat.at_2d::<f64>(0, 1)?, *mat.at_2d::<f64>(1, 0)?);
Ok(())
}
+
+#[test]
+fn line_iterator() -> Result<()> {
+ let mut data = [
+ 1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9,
+ 10, 11, 12u8,
+ ];
+ let mat = unsafe { Mat::new_rows_cols_with_data(4, 3, u8::typ(), data.as_mut_ptr() as *mut _, Mat_AUTO_STEP) }?;
+ let mut line_iter = imgproc::LineIterator::new(&mat, Point::new(0, 0), Point::new(2, 2), 8, false)?;
+ assert_eq!(3, line_iter.count());
+ assert_eq!(Point::new(0, 0), line_iter.pos()?);
+ assert_eq!(1, unsafe { *line_iter.try_deref_mut()?.as_ref().unwrap() });
+ line_iter.incr()?;
+ assert_eq!(Point::new(1, 1), line_iter.pos()?);
+ assert_eq!(5, unsafe { *line_iter.try_deref_mut()?.as_ref().unwrap() });
+ line_iter.incr()?;
+ assert_eq!(Point::new(2, 2), line_iter.pos()?);
+ assert_eq!(9, unsafe { *line_iter.try_deref_mut()?.as_ref().unwrap() });
+ Ok(())
+}

Add generation for increment and decrement operators