From f13fe7c6d52422f7e7dfa572c6ce9223b90923c8 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Wed, 3 Aug 2022 17:09:16 +0200 Subject: [PATCH] Adapted to other Sciplot and Nlohmann JSON API changes --- grapher/include/grapher/utils/json.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/grapher/include/grapher/utils/json.hpp b/grapher/include/grapher/utils/json.hpp index fd7e893..dbf1a61 100644 --- a/grapher/include/grapher/utils/json.hpp +++ b/grapher/include/grapher/utils/json.hpp @@ -27,13 +27,25 @@ std::vector get_values(benchmark_iteration_t const &iteration, /// present in b share the same key. grapher::json_t merge_into(grapher::json_t a, grapher::json_t const &b); +/// Generic conversion of a JSON field location to a std::string +template +inline std::string field_loc_to_string(T &&field_location) { + return std::string{std::forward(field_location)}; +} + +/// Specialized conversion of a JSON field location to a std::string +inline std::string +field_loc_to_string(grapher::json_t::json_pointer const &json_ptr) { + return json_ptr.to_string(); +} + /// Wraps json_t object access with error management. template inline grapher::json_t::const_reference json_at(grapher::json_t const &object, LocType const &field_location, const std::experimental::source_location loc = std::experimental::source_location::current()) { - std::string const field_location_str = field_location; + std::string const field_location_str = field_loc_to_string(field_location); check(object.contains(field_location), fmt::format("Empty field {}:\n{}", field_location_str, object.dump(2)), @@ -51,7 +63,7 @@ json_at_ref(grapher::json_t const &object, LocType const &field_location, using ValueType = std::decay_t; - std::string const field_location_str = field_location; + std::string const field_location_str = field_loc_to_string(field_location); check(object.contains(field_location), fmt::format("Empty field {}:\n{}", field_location_str, object.dump(2)), @@ -172,7 +184,7 @@ read_descriptors(grapher::json_t::array_t const &list); // Plotter configuration /// Plot saving helper function. -void save_plot(sciplot::Plot const &plot, std::string const &dest, +void save_plot(sciplot::Plot2D const &plot, std::string const &dest, grapher::json_t const &config); /// Returns the default configuration for apply_config.