diff --git a/include/openPMD/binding/python/Container.hpp b/include/openPMD/binding/python/Container.hpp index 2c37405a86..65b842c511 100644 --- a/include/openPMD/binding/python/Container.hpp +++ b/include/openPMD/binding/python/Container.hpp @@ -101,16 +101,14 @@ Class_ bind_container(Class_ &cl, std::string const &name) return cl; } -template < - typename Map, - typename holder_type = std::unique_ptr, - typename... Args> -py::class_ create_and_bind_container( - py::handle scope, std::string const &name, Args &&...args) +template +py::class_, Args...> +create_and_bind_container(py::handle scope, std::string const &name) { + using holder_type = std::unique_ptr; using KeyType = typename Map::key_type; using MappedType = typename Map::mapped_type; - using Class_ = py::class_; + using Class_ = py::class_; // If either type is a non-module-local bound type then make the map // binding non-local as well; otherwise (e.g. both types are either @@ -127,11 +125,8 @@ py::class_ create_and_bind_container( scope, name.c_str(), py::module_local(local), - py::multiple_inheritance(), - std::forward(args)...); + py::multiple_inheritance()); - // maybe move this to bind_container - cl.def(py::init()); return bind_container(cl, name); } } // namespace openPMD::detail diff --git a/src/binding/python/BaseRecord.cpp b/src/binding/python/BaseRecord.cpp index 4a0500d6ab..f1b7efd0cf 100644 --- a/src/binding/python/BaseRecord.cpp +++ b/src/binding/python/BaseRecord.cpp @@ -26,6 +26,7 @@ #include "openPMD/backend/Container.hpp" #include "openPMD/backend/MeshRecordComponent.hpp" #include "openPMD/backend/PatchRecordComponent.hpp" +#include "openPMD/binding/python/Container.hpp" #include "openPMD/binding/python/UnitDimension.hpp" namespace py = pybind11; @@ -37,29 +38,19 @@ void init_BaseRecord(py::module &m) Returns true if this record only contains a single component. )docstr"; - // py::class_< - // BaseRecord, - // Container >(m, - // "Base_Record_Base_Record_Component") .def_property_readonly( - // "unit_dimension", - // &BaseRecord::unitDimension, - // python::doc_unit_dimension) - // .def_property_readonly( - // "scalar", &BaseRecord::scalar, doc_scalar); - - py::class_< + detail::create_and_bind_container< BaseRecord, Container, RecordComponent>(m, "Base_Record_Record_Component") .def_property_readonly( "scalar", &BaseRecord::scalar, doc_scalar); - py::class_< + detail::create_and_bind_container< BaseRecord, Container, MeshRecordComponent>(m, "Base_Record_Mesh_Record_Component") .def_property_readonly( "scalar", &BaseRecord::scalar, doc_scalar); - py::class_< + detail::create_and_bind_container< BaseRecord, Container, PatchRecordComponent>(m, "Base_Record_Patch_Record_Component") diff --git a/src/binding/python/Container.cpp b/src/binding/python/Container.cpp index e8ebf5c27b..ab890eafe5 100644 --- a/src/binding/python/Container.cpp +++ b/src/binding/python/Container.cpp @@ -51,7 +51,7 @@ using PyPatchRecordContainer = Container; using PyRecordComponentContainer = Container; using PyMeshRecordComponentContainer = Container; using PyPatchRecordComponentContainer = Container; -using PyBaseRecordComponentContainer = Container; +// using PyBaseRecordComponentContainer = Container; PYBIND11_MAKE_OPAQUE(PyIterationContainer) PYBIND11_MAKE_OPAQUE(PyMeshContainer) PYBIND11_MAKE_OPAQUE(PyPartContainer) @@ -61,27 +61,42 @@ PYBIND11_MAKE_OPAQUE(PyPatchRecordContainer) PYBIND11_MAKE_OPAQUE(PyRecordComponentContainer) PYBIND11_MAKE_OPAQUE(PyMeshRecordComponentContainer) PYBIND11_MAKE_OPAQUE(PyPatchRecordComponentContainer) -PYBIND11_MAKE_OPAQUE(PyBaseRecordComponentContainer) +// PYBIND11_MAKE_OPAQUE(PyBaseRecordComponentContainer) + +namespace openPMD::detail +{ +template +void wrap_bind_container(py::handle scope, std::string const &name) +{ + create_and_bind_container(std::move(scope), name) + .def(py::init()); +} +} // namespace openPMD::detail void init_Container(py::module &m) { - ::detail::create_and_bind_container( + ::detail::create_and_bind_container( m, "Iteration_Container"); - ::detail::create_and_bind_container(m, "Mesh_Container"); - ::detail::create_and_bind_container( + ::detail::create_and_bind_container( + m, "Mesh_Container"); + ::detail::create_and_bind_container( m, "Particle_Container"); - ::detail::create_and_bind_container( + ::detail::create_and_bind_container( m, "Particle_Patches_Container"); - ::detail::create_and_bind_container( + ::detail::create_and_bind_container( m, "Record_Container"); - ::detail::create_and_bind_container( + ::detail::create_and_bind_container( m, "Patch_Record_Container"); - ::detail::create_and_bind_container( - m, "Record_Component_Container"); - ::detail::create_and_bind_container( - m, "Mesh_Record_Component_Container"); - ::detail::create_and_bind_container( - m, "Patch_Record_Component_Container"); - ::detail::create_and_bind_container( - m, "Base_Record_Component_Container"); + ::detail:: + create_and_bind_container( + m, "Record_Component_Container"); + ::detail:: + create_and_bind_container( + m, "Mesh_Record_Component_Container"); + ::detail::create_and_bind_container< + PyPatchRecordComponentContainer, + Attributable>(m, "Patch_Record_Component_Container"); + // ::detail::create_and_bind_container( + // m, "Base_Record_Component_Container"); }