From 23b71018ac5d0f0a66cb40fa69ddb1ae315c21bb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Mar 2022 00:31:20 +0100 Subject: [PATCH] kraken: csv: add writing functionality Once again, pretty naive, but it will do. --- src/csv/CMakeLists.txt | 2 ++ src/csv/write-csv.cc | 16 ++++++++++++++++ src/csv/write-csv.hh | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/csv/write-csv.cc create mode 100644 src/csv/write-csv.hh diff --git a/src/csv/CMakeLists.txt b/src/csv/CMakeLists.txt index 38e27b5..3821532 100644 --- a/src/csv/CMakeLists.txt +++ b/src/csv/CMakeLists.txt @@ -2,5 +2,7 @@ add_library(csv STATIC csv.hh read-csv.cc read-csv.hh + write-csv.cc + write-csv.hh ) target_link_libraries(csv PRIVATE common_options) diff --git a/src/csv/write-csv.cc b/src/csv/write-csv.cc new file mode 100644 index 0000000..186947c --- /dev/null +++ b/src/csv/write-csv.cc @@ -0,0 +1,16 @@ +#include "write-csv.hh" + +#include +#include +#include + +namespace kraken::csv { + +void write_csv(std::ostream& output, csv_type const& csv) { + for (const auto& line : csv) { + std::ranges::copy(line, + std::ostream_iterator{output, ","}); + } +} + +} // namespace kraken::csv diff --git a/src/csv/write-csv.hh b/src/csv/write-csv.hh new file mode 100644 index 0000000..d3dd402 --- /dev/null +++ b/src/csv/write-csv.hh @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include + +#include "csv/csv.hh" + +namespace kraken::csv { + +/// Write raw CSV data to an output-stream. +void write_csv(std::ostream& output, csv_type const& csv); + +} // namespace kraken::csv