From a9d3983426c78003bd42fa280844f441b3d62172 Mon Sep 17 00:00:00 2001 From: Lucas Czech Date: Wed, 15 May 2024 14:02:37 +0200 Subject: [PATCH] Add output target overload for cathedral save functions --- .../population/plotting/cathedral_plot.cpp | 23 +++++++++++++++---- .../population/plotting/cathedral_plot.hpp | 15 ++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/genesis/population/plotting/cathedral_plot.cpp b/lib/genesis/population/plotting/cathedral_plot.cpp index 0fd15ee3..a9c6dc47 100644 --- a/lib/genesis/population/plotting/cathedral_plot.cpp +++ b/lib/genesis/population/plotting/cathedral_plot.cpp @@ -222,10 +222,11 @@ genesis::utils::JsonDocument cathedral_plot_record_to_json_document( return document; } -void save_cathedral_plot_record_to_files( +void save_cathedral_plot_record_to_targets( genesis::utils::JsonDocument const& record_document, genesis::utils::Matrix const& record_value_matrix, - std::string const& base_path + std::shared_ptr json_target, + std::shared_ptr csv_target ) { using namespace genesis::utils; @@ -245,8 +246,22 @@ void save_cathedral_plot_record_to_files( } // Write both files, using their respective readers. - JsonWriter().write( record_document, to_file( base_path + ".json" )); - MatrixWriter( "," ).write( record_value_matrix, to_file( base_path + ".csv" )); + JsonWriter().write( record_document, json_target ); + MatrixWriter( "," ).write( record_value_matrix, csv_target ); +} + +void save_cathedral_plot_record_to_files( + genesis::utils::JsonDocument const& record_document, + genesis::utils::Matrix const& record_value_matrix, + std::string const& base_path +) { + using namespace genesis::utils; + save_cathedral_plot_record_to_targets( + record_document, + record_value_matrix, + to_file( base_path + ".json" ), + to_file( base_path + ".csv" ) + ); } void save_cathedral_plot_record_to_files( diff --git a/lib/genesis/population/plotting/cathedral_plot.hpp b/lib/genesis/population/plotting/cathedral_plot.hpp index 2a6f10ac..98c26539 100644 --- a/lib/genesis/population/plotting/cathedral_plot.hpp +++ b/lib/genesis/population/plotting/cathedral_plot.hpp @@ -34,6 +34,7 @@ #include "genesis/utils/color/color.hpp" #include "genesis/utils/color/heat_map.hpp" #include "genesis/utils/containers/matrix.hpp" +#include "genesis/utils/io/base_output_target.hpp" #include #include @@ -339,6 +340,20 @@ genesis::utils::JsonDocument cathedral_plot_record_to_json_document( CathedralPlotRecord const& record ); +/** + * @brief Save the record of a cathedral plot in a set of output targets. + * + * This overload allows to specify the targets directly, instead of creating fitting targets + * according to a file `base_path`. See save_cathedral_plot_record_to_files() for the file-based + * versions of this function. + */ +void save_cathedral_plot_record_to_targets( + genesis::utils::JsonDocument const& record_document, + genesis::utils::Matrix const& record_value_matrix, + std::shared_ptr json_target, + std::shared_ptr csv_target +); + /** * @brief Save the record of a cathedral plot in a set of files. *