11#pragma once
22
33#include < pybind11/pybind11.h>
4+ #include < wpi/units/core.hpp>
45
56namespace pybind11 {
67namespace detail {
@@ -26,14 +27,10 @@ namespace detail {
2627 foo(wpi::units::seconds<> tm = 10_ms); // if not careful, pybind11 will
2728 // store as 10 seconds
2829*/
29- template <wpi::units::ConversionFactorType ConversionFactor,
30- wpi::units::ArithmeticType T,
31- wpi::units::NumericalScaleType<T> NumericalScale>
32- struct type_caster <wpi::units::unit<ConversionFactor, T, NumericalScale>> {
33- using value_type = wpi::units::unit<ConversionFactor, T, NumericalScale>;
34-
30+ template <wpi::units::UnitType Unit>
31+ struct type_caster <Unit> {
3532 // TODO: there should be a way to include the type with this
36- PYBIND11_TYPE_CASTER (value_type , handle_type_name<value_type >::name);
33+ PYBIND11_TYPE_CASTER (Unit , handle_type_name<Unit >::name);
3734
3835 // Python -> C++
3936 bool load (handle src, bool convert) {
@@ -42,12 +39,12 @@ struct type_caster<wpi::units::unit<ConversionFactor, T, NumericalScale>> {
4239 if (!convert && !PyFloat_Check (src.ptr ()))
4340 return false ;
4441 auto cvted = PyFloat_AsDouble (src.ptr ());
45- value = value_type (cvted);
42+ value = Unit (cvted);
4643 return !(cvted == -1 && PyErr_Occurred ());
4744 }
4845
4946 // C++ -> Python
50- static handle cast (const value_type & src, return_value_policy /* policy */ ,
47+ static handle cast (const Unit& src, return_value_policy /* policy */ ,
5148 handle /* parent */ ) {
5249 return PyFloat_FromDouble (src.raw ());
5350 }
0 commit comments