opencv_binding_generator/settings/
func_companion_tweak.rs

1use std::collections::HashMap;
2
3use crate::func::FuncMatcher;
4
5pub type FuncCompanionTweak = FuncMatcher<'static, CompanionTweak>;
6
7#[derive(Debug, Clone, Copy)]
8pub enum CompanionTweak {
9	/// Don't generate the `*_def` function companion
10	SkipDefault,
11}
12
13pub fn func_companion_tweak_factory(module: &str) -> FuncCompanionTweak {
14	match module {
15		"dnn" => dnn_factory(),
16		"text" => text_factory(),
17		_ => FuncCompanionTweak::empty(),
18	}
19}
20
21fn dnn_factory() -> FuncCompanionTweak {
22	FuncMatcher::create(HashMap::from([(
23		"cv::dnn::Graph::append", // 2 functions with the same name and same non-default arguments lead to the name clash and ambiguous call in C++
24		vec![
25			(pred!(mut, ["layer", "outnames"]), CompanionTweak::SkipDefault),
26			(pred!(mut, ["layer", "outname"]), CompanionTweak::SkipDefault),
27		],
28	)]))
29}
30
31fn text_factory() -> FuncCompanionTweak {
32	FuncMatcher::create(HashMap::from([(
33		"cv::text::OCRBeamSearchDecoder::create",
34		vec![(
35			pred!(
36				mut,
37				[
38					"classifier",
39					"vocabulary",
40					"transition_probabilities_table",
41					"emission_probabilities_table",
42					"mode",
43					"beam_size"
44				],
45			),
46			CompanionTweak::SkipDefault, // with OpenCV 4.2 this leads to https://github.com/twistedfall/opencv-rust/issues/505
47		)],
48	)]))
49}
50
51impl CompanionTweak {
52	pub fn skip_default(&self) -> bool {
53		match self {
54			CompanionTweak::SkipDefault => true,
55		}
56	}
57}