|
22 | 22 | #include "openPMD/IO/Access.hpp" |
23 | 23 | #include "openPMD/IterationEncoding.hpp" |
24 | 24 | #include "openPMD/auxiliary/JSON.hpp" |
| 25 | +#include "openPMD/auxiliary/Variant.hpp" |
25 | 26 | #include "openPMD/binding/python/Pickle.hpp" |
26 | 27 | #include "openPMD/config.hpp" |
27 | 28 |
|
28 | 29 | #include "openPMD/binding/python/Common.hpp" |
| 30 | +#include <variant> |
29 | 31 |
|
30 | 32 | #if openPMD_HAVE_MPI |
31 | 33 | // re-implemented signatures: |
@@ -282,26 +284,60 @@ this method. |
282 | 284 | &Series::openPMDextension, |
283 | 285 | &Series::setOpenPMDextension) |
284 | 286 | .def_property("base_path", &Series::basePath, &Series::setBasePath) |
285 | | - .def_property( |
286 | | - "meshes_path", |
287 | | - &Series::meshesPath, |
288 | | - py::overload_cast<std::string const &>(&Series::setMeshesPath)) |
289 | 287 | .def("get_rank_table", &Series::rankTable, py::arg("collective")) |
290 | 288 | .def("set_rank_table", &Series::setRankTable, py::arg("my_rank_info")) |
291 | 289 | .def_property( |
292 | | - "particles_path", |
293 | | - &Series::particlesPath, |
294 | | - py::overload_cast<std::string const &>(&Series::setParticlesPath)) |
295 | | - .def_property( |
296 | | - "meshes_paths", |
297 | | - &Series::meshesPath, |
298 | | - py::overload_cast<std::vector<std::string> const &>( |
299 | | - &Series::setMeshesPath)) |
| 290 | + "meshes_path", |
| 291 | + [](Series &self) |
| 292 | + -> std::variant<std::string, std::vector<std::string>> { |
| 293 | + using res_t = |
| 294 | + std::variant<std::string, std::vector<std::string>>; |
| 295 | + auto res = self.meshesPaths(); |
| 296 | + if (res.size() == 1) |
| 297 | + { |
| 298 | + return res_t{std::move(res[0])}; |
| 299 | + } |
| 300 | + else |
| 301 | + { |
| 302 | + return res_t{std::move(res)}; |
| 303 | + } |
| 304 | + }, |
| 305 | + [](Series &self, |
| 306 | + std::variant<std::string, std::vector<std::string>> const &arg) |
| 307 | + -> Series & { |
| 308 | + std::visit( |
| 309 | + [&](auto const &arg_resolved) { |
| 310 | + self.setMeshesPath(arg_resolved); |
| 311 | + }, |
| 312 | + arg); |
| 313 | + return self; |
| 314 | + }) |
300 | 315 | .def_property( |
301 | | - "particles_paths", |
302 | | - &Series::particlesPath, |
303 | | - py::overload_cast<std::vector<std::string> const &>( |
304 | | - &Series::setParticlesPath)) |
| 316 | + "particles_path", |
| 317 | + [](Series &self) |
| 318 | + -> std::variant<std::string, std::vector<std::string>> { |
| 319 | + using res_t = |
| 320 | + std::variant<std::string, std::vector<std::string>>; |
| 321 | + auto res = self.particlesPaths(); |
| 322 | + if (res.size() == 1) |
| 323 | + { |
| 324 | + return res_t{std::move(res[0])}; |
| 325 | + } |
| 326 | + else |
| 327 | + { |
| 328 | + return res_t{std::move(res)}; |
| 329 | + } |
| 330 | + }, |
| 331 | + [](Series &self, |
| 332 | + std::variant<std::string, std::vector<std::string>> const &arg) |
| 333 | + -> Series & { |
| 334 | + std::visit( |
| 335 | + [&](auto const &arg_resolved) { |
| 336 | + self.setParticlesPath(arg_resolved); |
| 337 | + }, |
| 338 | + arg); |
| 339 | + return self; |
| 340 | + }) |
305 | 341 | .def_property("author", &Series::author, &Series::setAuthor) |
306 | 342 | .def_property( |
307 | 343 | "machine", |
|
0 commit comments