|
25 | 25 | #include "openPMD/IterationEncoding.hpp" |
26 | 26 | #include "openPMD/auxiliary/JSON.hpp" |
27 | 27 | #include "openPMD/binding/python/Common.hpp" |
| 28 | +#include "openPMD/auxiliary/Variant.hpp" |
28 | 29 | #include "openPMD/binding/python/Pickle.hpp" |
29 | 30 | #include "openPMD/binding/python/auxiliary.hpp" |
30 | 31 | #include "openPMD/config.hpp" |
|
33 | 34 |
|
34 | 35 | #include <optional> |
35 | 36 | #include <tuple> |
| 37 | +#include <variant> |
36 | 38 |
|
37 | 39 | #if openPMD_USE_FILESYSTEM_HEADER |
38 | 40 | #include <filesystem> |
@@ -419,26 +421,60 @@ this method. |
419 | 421 | &Series::openPMDextension, |
420 | 422 | &Series::setOpenPMDextension) |
421 | 423 | .def_property("base_path", &Series::basePath, &Series::setBasePath) |
422 | | - .def_property( |
423 | | - "meshes_path", |
424 | | - &Series::meshesPath, |
425 | | - py::overload_cast<std::string const &>(&Series::setMeshesPath)) |
426 | 424 | .def("get_rank_table", &Series::rankTable, py::arg("collective")) |
427 | 425 | .def("set_rank_table", &Series::setRankTable, py::arg("my_rank_info")) |
428 | 426 | .def_property( |
429 | | - "particles_path", |
430 | | - &Series::particlesPath, |
431 | | - py::overload_cast<std::string const &>(&Series::setParticlesPath)) |
432 | | - .def_property( |
433 | | - "meshes_paths", |
434 | | - &Series::meshesPath, |
435 | | - py::overload_cast<std::vector<std::string> const &>( |
436 | | - &Series::setMeshesPath)) |
| 427 | + "meshes_path", |
| 428 | + [](Series &self) |
| 429 | + -> std::variant<std::string, std::vector<std::string>> { |
| 430 | + using res_t = |
| 431 | + std::variant<std::string, std::vector<std::string>>; |
| 432 | + auto res = self.meshesPaths(); |
| 433 | + if (res.size() == 1) |
| 434 | + { |
| 435 | + return res_t{std::move(res[0])}; |
| 436 | + } |
| 437 | + else |
| 438 | + { |
| 439 | + return res_t{std::move(res)}; |
| 440 | + } |
| 441 | + }, |
| 442 | + [](Series &self, |
| 443 | + std::variant<std::string, std::vector<std::string>> const &arg) |
| 444 | + -> Series & { |
| 445 | + std::visit( |
| 446 | + [&](auto const &arg_resolved) { |
| 447 | + self.setMeshesPath(arg_resolved); |
| 448 | + }, |
| 449 | + arg); |
| 450 | + return self; |
| 451 | + }) |
437 | 452 | .def_property( |
438 | | - "particles_paths", |
439 | | - &Series::particlesPath, |
440 | | - py::overload_cast<std::vector<std::string> const &>( |
441 | | - &Series::setParticlesPath)) |
| 453 | + "particles_path", |
| 454 | + [](Series &self) |
| 455 | + -> std::variant<std::string, std::vector<std::string>> { |
| 456 | + using res_t = |
| 457 | + std::variant<std::string, std::vector<std::string>>; |
| 458 | + auto res = self.particlesPaths(); |
| 459 | + if (res.size() == 1) |
| 460 | + { |
| 461 | + return res_t{std::move(res[0])}; |
| 462 | + } |
| 463 | + else |
| 464 | + { |
| 465 | + return res_t{std::move(res)}; |
| 466 | + } |
| 467 | + }, |
| 468 | + [](Series &self, |
| 469 | + std::variant<std::string, std::vector<std::string>> const &arg) |
| 470 | + -> Series & { |
| 471 | + std::visit( |
| 472 | + [&](auto const &arg_resolved) { |
| 473 | + self.setParticlesPath(arg_resolved); |
| 474 | + }, |
| 475 | + arg); |
| 476 | + return self; |
| 477 | + }) |
442 | 478 | .def_property("author", &Series::author, &Series::setAuthor) |
443 | 479 | .def_property( |
444 | 480 | "machine", |
|
0 commit comments