Skip to content

Commit 15ee3d7

Browse files
committed
Update robotpy-wpiutil for beta2
1 parent fd07128 commit 15ee3d7

File tree

2 files changed

+7
-53
lines changed

2 files changed

+7
-53
lines changed

subprojects/robotpy-wpiutil/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ scan_headers_ignore = [
2525
"google/*",
2626
"wpi/*",
2727
"wpystruct_fns.h",
28+
"pb.h",
29+
"pb_common.h",
30+
"pb_decode.h",
31+
"pb_encode.h",
2832
]
2933

3034
[tool.robotpy-build.wrappers."wpiutil"]

subprojects/robotpy-wpiutil/wpiutil/src/type_casters/wpi_string_map_caster.h

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#pragma once
33

44
#include <pybind11/pybind11.h>
5+
#include <pybind11/stl.h>
56

67
#include <wpi/StringMap.h>
78

@@ -10,60 +11,9 @@ namespace pybind11
1011
namespace detail
1112
{
1213

13-
1414
template <typename Value>
15-
struct type_caster<wpi::StringMap<Value>> {
16-
using Type = wpi::StringMap<Value>;
17-
using Key = std::string_view;
18-
19-
using key_conv = make_caster<Key>;
20-
using value_conv = make_caster<Value>;
21-
22-
bool load(handle src, bool convert) {
23-
if (!isinstance<dict>(src)) {
24-
return false;
25-
}
26-
auto d = reinterpret_borrow<dict>(src);
27-
value.clear();
28-
for (auto it : d) {
29-
key_conv kconv;
30-
value_conv vconv;
31-
if (!kconv.load(it.first.ptr(), convert) || !vconv.load(it.second.ptr(), convert)) {
32-
return false;
33-
}
34-
// this is different from pybind11/stl.h map_caster
35-
value.try_emplace(cast_op<Key &&>(std::move(kconv)), cast_op<Value &&>(std::move(vconv)));
36-
}
37-
return true;
38-
}
39-
40-
template <typename T>
41-
static handle cast(T &&src, return_value_policy policy, handle parent) {
42-
dict d;
43-
return_value_policy policy_key = policy;
44-
return_value_policy policy_value = policy;
45-
if (!std::is_lvalue_reference<T>::value) {
46-
policy_key = return_value_policy_override<Key>::policy(policy_key);
47-
policy_value = return_value_policy_override<Value>::policy(policy_value);
48-
}
49-
for (auto &&kv : src) {
50-
// getKey/getValue is different from pybind11/stl.h map_caster
51-
auto key = reinterpret_steal<object>(
52-
key_conv::cast(forward_like<T>(kv.getKey()), policy_key, parent));
53-
auto value = reinterpret_steal<object>(
54-
value_conv::cast(forward_like<T>(kv.getValue()), policy_value, parent));
55-
if (!key || !value) {
56-
return handle();
57-
}
58-
d[std::move(key)] = std::move(value);
59-
}
60-
return d.release();
61-
}
62-
63-
PYBIND11_TYPE_CASTER(Type,
64-
const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name
65-
+ const_name("]"));
66-
};
15+
struct type_caster<wpi::StringMap<Value>>
16+
: map_caster<wpi::StringMap<Value>, std::string, Value> { };
6717

6818
} // namespace detail
6919
} // namespace pybind11

0 commit comments

Comments
 (0)