@@ -23,135 +23,135 @@ PYBIND11_MAKE_OPAQUE(std::unordered_map<std::int8_t, dai::BoardConfig::UART>);
23
23
// Patch for bind_map naming
24
24
// Remove if it gets mainlined in pybind11
25
25
namespace pybind11 {
26
-
27
- template <typename Map, typename holder_type = std::unique_ptr<Map>, typename ... Args>
28
- class_<Map, holder_type> bind_map_patched (handle scope, const std::string &name, Args &&...args) {
29
- using KeyType = typename Map::key_type;
30
- using MappedType = typename Map::mapped_type;
31
- using KeysView = detail::keys_view<Map>;
32
- using ValuesView = detail::values_view<Map>;
33
- using ItemsView = detail::items_view<Map>;
34
- using Class_ = class_<Map, holder_type>;
35
-
36
- // If either type is a non-module-local bound type then make the map binding non-local as well;
37
- // otherwise (e.g. both types are either module-local or converting) the map will be
38
- // module-local.
39
- auto *tinfo = detail::get_type_info (typeid (MappedType));
40
- bool local = !tinfo || tinfo->module_local ;
41
- if (local) {
42
- tinfo = detail::get_type_info (typeid (KeyType));
43
- local = !tinfo || tinfo->module_local ;
44
- }
45
-
46
- Class_ cl (scope, name.c_str (), pybind11::module_local (local), std::forward<Args>(args)...);
47
- class_<KeysView> keys_view (
48
- scope, (" KeysView_" + name).c_str (), pybind11::module_local (local));
49
- class_<ValuesView> values_view (
50
- scope, (" ValuesView_" + name).c_str (), pybind11::module_local (local));
51
- class_<ItemsView> items_view (
52
- scope, (" ItemsView_" + name).c_str (), pybind11::module_local (local));
53
-
54
- cl.def (init<>());
55
-
56
- // Register stream insertion operator (if possible)
57
- detail::map_if_insertion_operator<Map, Class_>(cl, name);
58
-
59
- cl.def (
60
- " __bool__" ,
61
- [](const Map &m) -> bool { return !m.empty (); },
62
- " Check whether the map is nonempty" );
63
-
64
- cl.def (
65
- " __iter__" ,
66
- [](Map &m) { return make_key_iterator (m.begin (), m.end ()); },
67
- keep_alive<0 , 1 >() /* Essential: keep map alive while iterator exists */
68
- );
69
-
70
- cl.def (
71
- " keys" ,
72
- [](Map &m) { return KeysView{m}; },
73
- keep_alive<0 , 1 >() /* Essential: keep map alive while view exists */
74
- );
75
-
76
- cl.def (
77
- " values" ,
78
- [](Map &m) { return ValuesView{m}; },
79
- keep_alive<0 , 1 >() /* Essential: keep map alive while view exists */
80
- );
81
-
82
- cl.def (
83
- " items" ,
84
- [](Map &m) { return ItemsView{m}; },
85
- keep_alive<0 , 1 >() /* Essential: keep map alive while view exists */
86
- );
87
-
88
- cl.def (
89
- " __getitem__" ,
90
- [](Map &m, const KeyType &k) -> MappedType & {
91
- auto it = m.find (k);
92
- if (it == m.end ()) {
93
- throw key_error ();
94
- }
95
- return it->second ;
96
- },
97
- return_value_policy::reference_internal // ref + keepalive
98
- );
99
-
100
- cl.def (" __contains__" , [](Map &m, const KeyType &k) -> bool {
101
- auto it = m.find (k);
102
- if (it == m.end ()) {
103
- return false ;
104
- }
105
- return true ;
106
- });
107
- // Fallback for when the object is not of the key type
108
- cl.def (" __contains__" , [](Map &, const object &) -> bool { return false ; });
109
-
110
- // Assignment provided only if the type is copyable
111
- detail::map_assignment<Map, Class_>(cl);
112
-
113
- cl.def (" __delitem__" , [](Map &m, const KeyType &k) {
114
- auto it = m.find (k);
115
- if (it == m.end ()) {
116
- throw key_error ();
117
- }
118
- m.erase (it);
119
- });
120
-
121
- cl.def (" __len__" , &Map::size);
122
-
123
- keys_view.def (" __len__" , [](KeysView &view) { return view.map .size (); });
124
- keys_view.def (
125
- " __iter__" ,
126
- [](KeysView &view) { return make_key_iterator (view.map .begin (), view.map .end ()); },
127
- keep_alive<0 , 1 >() /* Essential: keep view alive while iterator exists */
128
- );
129
- keys_view.def (" __contains__" , [](KeysView &view, const KeyType &k) -> bool {
130
- auto it = view.map .find (k);
131
- if (it == view.map .end ()) {
132
- return false ;
133
- }
134
- return true ;
135
- });
136
- // Fallback for when the object is not of the key type
137
- keys_view.def (" __contains__" , [](KeysView &, const object &) -> bool { return false ; });
138
-
139
- values_view.def (" __len__" , [](ValuesView &view) { return view.map .size (); });
140
- values_view.def (
141
- " __iter__" ,
142
- [](ValuesView &view) { return make_value_iterator (view.map .begin (), view.map .end ()); },
143
- keep_alive<0 , 1 >() /* Essential: keep view alive while iterator exists */
144
- );
145
-
146
- items_view.def (" __len__" , [](ItemsView &view) { return view.map .size (); });
147
- items_view.def (
148
- " __iter__" ,
149
- [](ItemsView &view) { return make_iterator (view.map .begin (), view.map .end ()); },
150
- keep_alive<0 , 1 >() /* Essential: keep view alive while iterator exists */
151
- );
152
-
153
- return cl;
154
- }
26
+ // TODO(Morato) - check if fixed, doesn't compile on v2.11.1
27
+ // template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args>
28
+ // class_<Map, holder_type> bind_map_patched(handle scope, const std::string &name, Args &&...args) {
29
+ // using KeyType = typename Map::key_type;
30
+ // using MappedType = typename Map::mapped_type;
31
+ // using KeysView = detail::keys_view<Map>;
32
+ // using ValuesView = detail::values_view<Map>;
33
+ // using ItemsView = detail::items_view<Map>;
34
+ // using Class_ = class_<Map, holder_type>;
35
+
36
+ // // If either type is a non-module-local bound type then make the map binding non-local as well;
37
+ // // otherwise (e.g. both types are either module-local or converting) the map will be
38
+ // // module-local.
39
+ // auto *tinfo = detail::get_type_info(typeid(MappedType));
40
+ // bool local = !tinfo || tinfo->module_local;
41
+ // if (local) {
42
+ // tinfo = detail::get_type_info(typeid(KeyType));
43
+ // local = !tinfo || tinfo->module_local;
44
+ // }
45
+
46
+ // Class_ cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(args)...);
47
+ // class_<KeysView> keys_view(
48
+ // scope, ("KeysView_" + name).c_str(), pybind11::module_local(local));
49
+ // class_<ValuesView> values_view(
50
+ // scope, ("ValuesView_" + name).c_str(), pybind11::module_local(local));
51
+ // class_<ItemsView> items_view(
52
+ // scope, ("ItemsView_" + name).c_str(), pybind11::module_local(local));
53
+
54
+ // cl.def(init<>());
55
+
56
+ // // Register stream insertion operator (if possible)
57
+ // detail::map_if_insertion_operator<Map, Class_>(cl, name);
58
+
59
+ // cl.def(
60
+ // "__bool__",
61
+ // [](const Map &m) -> bool { return !m.empty(); },
62
+ // "Check whether the map is nonempty");
63
+
64
+ // cl.def(
65
+ // "__iter__",
66
+ // [](Map &m) { return make_key_iterator(m.begin(), m.end()); },
67
+ // keep_alive<0, 1>() /* Essential: keep map alive while iterator exists */
68
+ // );
69
+
70
+ // cl.def(
71
+ // "keys",
72
+ // [](Map &m) { return KeysView{m}; },
73
+ // keep_alive<0, 1>() /* Essential: keep map alive while view exists */
74
+ // );
75
+
76
+ // cl.def(
77
+ // "values",
78
+ // [](Map &m) { return ValuesView{m}; },
79
+ // keep_alive<0, 1>() /* Essential: keep map alive while view exists */
80
+ // );
81
+
82
+ // cl.def(
83
+ // "items",
84
+ // [](Map &m) { return ItemsView{m}; },
85
+ // keep_alive<0, 1>() /* Essential: keep map alive while view exists */
86
+ // );
87
+
88
+ // cl.def(
89
+ // "__getitem__",
90
+ // [](Map &m, const KeyType &k) -> MappedType & {
91
+ // auto it = m.find(k);
92
+ // if (it == m.end()) {
93
+ // throw key_error();
94
+ // }
95
+ // return it->second;
96
+ // },
97
+ // return_value_policy::reference_internal // ref + keepalive
98
+ // );
99
+
100
+ // cl.def("__contains__", [](Map &m, const KeyType &k) -> bool {
101
+ // auto it = m.find(k);
102
+ // if (it == m.end()) {
103
+ // return false;
104
+ // }
105
+ // return true;
106
+ // });
107
+ // // Fallback for when the object is not of the key type
108
+ // cl.def("__contains__", [](Map &, const object &) -> bool { return false; });
109
+
110
+ // // Assignment provided only if the type is copyable
111
+ // detail::map_assignment<Map, Class_>(cl);
112
+
113
+ // cl.def("__delitem__", [](Map &m, const KeyType &k) {
114
+ // auto it = m.find(k);
115
+ // if (it == m.end()) {
116
+ // throw key_error();
117
+ // }
118
+ // m.erase(it);
119
+ // });
120
+
121
+ // cl.def("__len__", &Map::size);
122
+
123
+ // keys_view.def("__len__", [](KeysView &view) { return view.map.size(); });
124
+ // keys_view.def(
125
+ // "__iter__",
126
+ // [](KeysView &view) { return make_key_iterator(view.map.begin(), view.map.end()); },
127
+ // keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */
128
+ // );
129
+ // keys_view.def("__contains__", [](KeysView &view, const KeyType &k) -> bool {
130
+ // auto it = view.map.find(k);
131
+ // if (it == view.map.end()) {
132
+ // return false;
133
+ // }
134
+ // return true;
135
+ // });
136
+ // // Fallback for when the object is not of the key type
137
+ // keys_view.def("__contains__", [](KeysView &, const object &) -> bool { return false; });
138
+
139
+ // values_view.def("__len__", [](ValuesView &view) { return view.map.size(); });
140
+ // values_view.def(
141
+ // "__iter__",
142
+ // [](ValuesView &view) { return make_value_iterator(view.map.begin(), view.map.end()); },
143
+ // keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */
144
+ // );
145
+
146
+ // items_view.def("__len__", [](ItemsView &view) { return view.map.size(); });
147
+ // items_view.def(
148
+ // "__iter__",
149
+ // [](ItemsView &view) { return make_iterator(view.map.begin(), view.map.end()); },
150
+ // keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */
151
+ // );
152
+
153
+ // return cl;
154
+ // }
155
155
156
156
} // namespace pybind11
157
157
@@ -348,9 +348,10 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
348
348
py::class_<PyClock> clock (m, " Clock" );
349
349
350
350
351
- py::bind_map_patched<std::unordered_map<std::int8_t , dai::BoardConfig::GPIO>>(boardConfig, " GPIOMap" );
352
- py::bind_map_patched<std::unordered_map<std::int8_t , dai::BoardConfig::UART>>(boardConfig, " UARTMap" );
353
-
351
+ // py::bind_map_patched<std::unordered_map<std::int8_t, dai::BoardConfig::GPIO>>(boardConfig, "GPIOMap");
352
+ // py::bind_map_patched<std::unordered_map<std::int8_t, dai::BoardConfig::UART>>(boardConfig, "UARTMap");
353
+ py::bind_map<std::unordered_map<std::int8_t , dai::BoardConfig::GPIO>>(boardConfig, " GPIOMap" );
354
+ py::bind_map<std::unordered_map<std::int8_t , dai::BoardConfig::UART>>(boardConfig, " UARTMap" );
354
355
355
356
// pybind11 limitation of having actual classes as exceptions
356
357
// Possible but requires a larger workaround
0 commit comments