Skip to content

Commit

Permalink
Add output target overload for cathedral save functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lczech committed May 15, 2024
1 parent 940ee1a commit a9d3983
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/genesis/population/plotting/cathedral_plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> const& record_value_matrix,
std::string const& base_path
std::shared_ptr<genesis::utils::BaseOutputTarget> json_target,
std::shared_ptr<genesis::utils::BaseOutputTarget> csv_target
) {
using namespace genesis::utils;

Expand All @@ -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<double>( "," ).write( record_value_matrix, to_file( base_path + ".csv" ));
JsonWriter().write( record_document, json_target );
MatrixWriter<double>( "," ).write( record_value_matrix, csv_target );
}

void save_cathedral_plot_record_to_files(
genesis::utils::JsonDocument const& record_document,
genesis::utils::Matrix<double> 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(
Expand Down
15 changes: 15 additions & 0 deletions lib/genesis/population/plotting/cathedral_plot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cassert>
#include <cmath>
Expand Down Expand Up @@ -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<double> const& record_value_matrix,
std::shared_ptr<genesis::utils::BaseOutputTarget> json_target,
std::shared_ptr<genesis::utils::BaseOutputTarget> csv_target
);

/**
* @brief Save the record of a cathedral plot in a set of files.
*
Expand Down

0 comments on commit a9d3983

Please sign in to comment.