File indexing completed on 2025-12-11 09:40:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <algorithm>
0012
0013 #include <pybind11/pybind11.h>
0014
0015 namespace ActsPython {
0016
0017 struct Context {
0018 std::unordered_map<std::string, pybind11::module_> modules;
0019
0020 pybind11::module_& get(const std::string& name) { return modules.at(name); }
0021
0022 template <typename... Args>
0023 auto get(Args&&... args)
0024 requires(sizeof...(Args) >= 2)
0025 {
0026 return std::make_tuple((modules.at(args))...);
0027 }
0028 };
0029
0030
0031
0032
0033 inline void patchClassesWithConfig(pybind11::module_& m) {
0034 pybind11::module::import("acts._adapter").attr("_patch_config")(m);
0035 }
0036
0037
0038
0039
0040 template <typename T>
0041 void patchKwargsConstructor(T& c) {
0042 pybind11::module::import("acts._adapter").attr("_patchKwargsConstructor")(c);
0043 }
0044
0045
0046 template <typename T, typename Ur, typename Ut>
0047 void pythonRangeProperty(T& obj, const std::string& name, Ur Ut::*begin,
0048 Ur Ut::*end) {
0049 obj.def_property(
0050 name.c_str(), [=](Ut& self) { return std::pair{self.*begin, self.*end}; },
0051 [=](Ut& self, std::pair<Ur, Ur> p) {
0052 self.*begin = p.first;
0053 self.*end = p.second;
0054 });
0055 }
0056
0057 }