diff --git a/include/openPMD/auxiliary/JSON_internal.hpp b/include/openPMD/auxiliary/JSON_internal.hpp index 98b58fba7b..a61164bfa1 100644 --- a/include/openPMD/auxiliary/JSON_internal.hpp +++ b/include/openPMD/auxiliary/JSON_internal.hpp @@ -76,10 +76,7 @@ namespace json * * @return nlohmann::json& */ - inline nlohmann::json &json() - { - return *m_positionInOriginal; - } + nlohmann::json &json(); /** * @brief Access the underlying JSON value @@ -89,21 +86,7 @@ namespace json * `tracingJSON[arg1][arg2][arg3].json()`. * @return nlohmann::json& */ - template - inline nlohmann::json &json(Arg &&arg, Args &&...args) - { - [[maybe_unused]] auto do_trace = - [subhandle = this->operator[](arg)](auto const &key) mutable { - subhandle = subhandle[key]; - }; - (do_trace(args), ...); - nlohmann::json *res = &m_positionInOriginal->operator[](arg); - [[maybe_unused]] auto get_res = [&res](auto const &key) { - res = &(*res)[key]; - }; - (get_res(args), ...); - return *res; - } + nlohmann::json &json(std::vector path); template TracingJSON operator[](Key &&key); diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index ada66deec3..2946b047f0 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -1528,7 +1528,7 @@ adios2::Mode ADIOS2IOHandlerImpl::adios2AccessMode(std::string const &fullPath) if (m_config.json().contains("engine") && m_config["engine"].json().contains("access_mode")) { - auto const &access_mode_json = m_config.json("engine", "access_mode"); + auto const &access_mode_json = m_config.json({"engine", "access_mode"}); auto maybe_access_mode_string = json::asLowerCaseStringDynamic(access_mode_json); if (!maybe_access_mode_string.has_value()) diff --git a/src/IO/HDF5/ParallelHDF5IOHandler.cpp b/src/IO/HDF5/ParallelHDF5IOHandler.cpp index 2504babbeb..e1192c8a9c 100644 --- a/src/IO/HDF5/ParallelHDF5IOHandler.cpp +++ b/src/IO/HDF5/ParallelHDF5IOHandler.cpp @@ -231,7 +231,7 @@ ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl( { return std::nullopt; } - auto const &val = vfd_json_config.json(key); + auto const &val = vfd_json_config.json({key}); if (val.is_number_integer()) { return val.get(); @@ -250,7 +250,7 @@ ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl( { return std::nullopt; } - auto const &val = vfd_json_config.json(key); + auto const &val = vfd_json_config.json({key}); if (auto str_val = json::asLowerCaseStringDynamic(val); str_val.has_value()) { diff --git a/src/auxiliary/JSON.cpp b/src/auxiliary/JSON.cpp index 7c96221026..8b758fe70e 100644 --- a/src/auxiliary/JSON.cpp +++ b/src/auxiliary/JSON.cpp @@ -60,6 +60,29 @@ TracingJSON::TracingJSON(ParsedConfig parsedConfig) std::move(parsedConfig.config), parsedConfig.originallySpecifiedAs} {} +nlohmann::json &TracingJSON::json() +{ + return *m_positionInOriginal; +} + +nlohmann::json &TracingJSON::json(std::vector paths) +{ + if (paths.empty()) + { + return json(); + } + auto it = paths.begin(); + auto end = paths.end(); + nlohmann::json *res = &m_positionInOriginal->operator[](*it); + auto subhandle = this->operator[](*it); + for (++it; it != end; ++it) + { + subhandle = subhandle[*it]; + res = &(*res)[*it]; + } + return *res; +} + nlohmann::json const &TracingJSON::getShadow() const { return *m_positionInShadow;