File indexing completed on 2026-11-26 09:25:00
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <type_traits>
0012 #include <utility>
0013
0014 #include <pybind11/pybind11.h>
0015
0016
0017
0018 namespace ActsPython::EventDataHelpers {
0019
0020
0021
0022 template <typename Proxy, typename Access>
0023 using EigenValueT = typename std::decay_t<decltype(std::declval<Access>()(
0024 std::declval<const Proxy&>()))>::PlainObject;
0025
0026
0027
0028
0029 template <typename Cls, typename Access>
0030 void bindEigenReadonly(Cls& cls, const char* name, Access access) {
0031 using Proxy = typename Cls::type;
0032 using Value = EigenValueT<Proxy, Access>;
0033 cls.def_property_readonly(
0034 name, [access](const Proxy& self) { return Value{access(self)}; });
0035 }
0036
0037
0038
0039
0040 template <typename Cls, typename Access>
0041 void bindEigen(Cls& cls, const char* name, Access access) {
0042 using Proxy = typename Cls::type;
0043 using Value = EigenValueT<Proxy, Access>;
0044 auto get = [access](const Proxy& self) { return Value{access(self)}; };
0045 if constexpr (Proxy::ReadOnly) {
0046 cls.def_property_readonly(name, get);
0047 } else {
0048 cls.def_property(
0049 name, get, [access](Proxy& self, const Value& v) { access(self) = v; });
0050 }
0051 }
0052
0053
0054
0055
0056 template <typename Cls, typename Access>
0057 void bindScalar(Cls& cls, const char* name, Access access) {
0058 using Proxy = typename Cls::type;
0059 using T = std::decay_t<decltype(access(std::declval<const Proxy&>()))>;
0060 auto get = [access](const Proxy& self) -> T { return access(self); };
0061 if constexpr (Proxy::ReadOnly) {
0062 cls.def_property_readonly(name, get);
0063 } else {
0064 cls.def_property(name, get,
0065 [access](Proxy& self, T v) { access(self) = v; });
0066 }
0067 }
0068
0069 }