opencv_binding_generator/settings/
property_tweaks.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::collections::HashMap;

pub type PropertyTweaks = HashMap<&'static str, PropertyTweak<'static>>;

#[derive(Debug)]
pub struct PropertyTweak<'l> {
	pub rename: Option<&'l str>,
	pub read_write: Option<PropertyReadWrite>,
}

/// Rename property, format: (cpp_refname -> rust_custom_leafname)
pub fn property_tweaks_factory(module: &str) -> PropertyTweaks {
	match module {
		"core" => HashMap::from([
			(
				"cv::Mat::size",
				PropertyTweak {
					rename: Some("mat_size"),
					..PropertyTweak::none()
				},
			),
			(
				"cv::Mat::step",
				PropertyTweak {
					rename: Some("mat_step"),
					read_write: Some(PropertyReadWrite::ReadOnly), // MatStep type prevents assignment
				},
			),
			(
				"cv::UMat::size",
				PropertyTweak {
					rename: Some("mat_size"),
					..PropertyTweak::none()
				},
			),
			(
				"cv::UMat::step",
				PropertyTweak {
					rename: Some("mat_step"),
					read_write: Some(PropertyReadWrite::ReadOnly), // MatStep type prevents assignment
				},
			),
		]),
		_ => HashMap::new(),
	}
}

impl PropertyTweak<'_> {
	pub fn none() -> PropertyTweak<'static> {
		PropertyTweak {
			rename: None,
			read_write: None,
		}
	}
}

#[derive(Clone, Copy, Debug)]
pub enum PropertyReadWrite {
	ReadOnly,
	ReadWrite,
}

impl PropertyReadWrite {
	pub fn is_read(self) -> bool {
		match self {
			PropertyReadWrite::ReadOnly | PropertyReadWrite::ReadWrite => true,
		}
	}

	pub fn is_write(self) -> bool {
		match self {
			PropertyReadWrite::ReadWrite => true,
			PropertyReadWrite::ReadOnly => false,
		}
	}
}