opencv_binding_generator/settings/
func_companion_tweak.rs

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