opencv_binding_generator/settings/
func_specialize.rs

1use std::collections::HashMap;
2
3use super::TypeRefFactory;
4use crate::func::FuncMatcher;
5use crate::type_ref::TypeRefDesc;
6use crate::SupportedModule;
7
8pub type FuncSpecialize = FuncMatcher<'static, Vec<FuncSpec>>;
9
10pub type FuncSpec = (&'static str, HashMap<&'static str, TypeRefFactory>);
11
12// todo: get rid of func_specialize in favor of just injecting manual functions
13pub fn func_specialize_factory(module: SupportedModule) -> FuncSpecialize {
14	match module {
15		SupportedModule::Core => FuncMatcher::create(HashMap::from([(
16			"cv::CommandLineParser::get",
17			vec![
18				(
19					pred!(const, ["name", "space_delete"]),
20					vec![
21						("+_bool", HashMap::from([("T", TypeRefDesc::bool as _)])),
22						("+_i32", HashMap::from([("T", TypeRefDesc::int as _)])),
23						("+_f64", HashMap::from([("T", TypeRefDesc::double as _)])),
24						("+_str", HashMap::from([("T", TypeRefDesc::cv_string as _)])),
25						("+_u64", HashMap::from([("T", TypeRefDesc::uint64_t as _)])),
26					],
27				),
28				(
29					pred!(const, ["index", "space_delete"]),
30					vec![
31						("+_bool_idx", HashMap::from([("T", TypeRefDesc::bool as _)])),
32						("+_i32_idx", HashMap::from([("T", TypeRefDesc::int as _)])),
33						("+_f64_idx", HashMap::from([("T", TypeRefDesc::double as _)])),
34						("+_str_idx", HashMap::from([("T", TypeRefDesc::cv_string as _)])),
35						("+_u64_idx", HashMap::from([("T", TypeRefDesc::uint64_t as _)])),
36					],
37				),
38			],
39		)])),
40		SupportedModule::Dnn => FuncMatcher::create(HashMap::from([
41			(
42				"cv::dnn::Dict::set",
43				vec![(
44					pred!(mut, ["key", "value"]),
45					vec![
46						("+_str", HashMap::from([("const T", TypeRefDesc::cv_string as _)])),
47						("+", HashMap::from([("const T", TypeRefDesc::cv_dnn_dict_value as _)])),
48						("+_f64", HashMap::from([("const T", TypeRefDesc::double as _)])),
49						("+_i64", HashMap::from([("const T", TypeRefDesc::int64_t as _)])),
50					],
51				)],
52			),
53			(
54				"cv::dnn::DictValue::get",
55				vec![(
56					pred!(const, ["idx"]),
57					vec![
58						("+_str", HashMap::from([("T", TypeRefDesc::cv_string as _)])),
59						("+_f64", HashMap::from([("T", TypeRefDesc::double as _)])),
60						("+_i32", HashMap::from([("T", TypeRefDesc::int as _)])),
61						("+_i64", HashMap::from([("T", TypeRefDesc::int64_t as _)])),
62					],
63				)],
64			),
65		])),
66		_ => FuncMatcher::empty(),
67	}
68}