Dynamical System Framework
Loading...
Searching...
No Matches
csv_writer.hpp File Reference

Helpers to write dsf's delimiter-separated output files. More...

#include <csv.hpp>
#include <format>
#include <fstream>
#include <ios>
#include <stdexcept>
#include <string>

Typedefs

using dsf::utility::CSVRowWriter = csv::DelimWriter<std::ofstream, ';', '"'>
 The writer used for dsf's CSV artifacts.

Functions

std::ofstream dsf::utility::openCSVFile (std::string const &fileName, std::ios::openmode const mode=std::ios::app)
 Open a CSV file for writing.

Detailed Description

Helpers to write dsf's delimiter-separated output files.

This file wraps the csv-parser writer with the conventions dsf uses for its CSV artifacts, so that every component writing one agrees on the separator and on how the output stream is opened.

Note
Internal header: it is excluded from the install because it exposes csv-parser, which dsf links as a build-only private dependency. Include it from dsf implementation files only, never from an installed header.

Typedef Documentation

◆ CSVRowWriter

using dsf::utility::CSVRowWriter = csv::DelimWriter<std::ofstream, ';', '"'>

The writer used for dsf's CSV artifacts.

dsf CSV files are semicolon-separated. csv::DelimWriter takes the delimiter as a template parameter and only holds a reference to the output stream, so the caller owns the std::ofstream it is built on and must keep it alive for at least as long as the writer.

Function Documentation

◆ openCSVFile()

std::ofstream dsf::utility::openCSVFile ( std::string const & fileName,
std::ios::openmode const mode = std::ios::app )
inline

Open a CSV file for writing.

Parameters
fileNameThe path of the file to open
modeThe open mode. Defaults to appending, so that rows flushed over several calls accumulate in the same file
Returns
std::ofstream The output stream, which must outlive any writer built on it
Exceptions
std::runtime_errorIf the file cannot be opened