Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
Brush::Util::CsvWriter Class Reference

Minimal RFC 4180 CSV writer used by the run logs. More...

#include <csv.h>

Collaboration diagram for Brush::Util::CsvWriter:

Public Member Functions

 CsvWriter ()=default
 CsvWriter (const std::string &path, const std::vector< std::string > &header)
void open (const std::string &path, const std::vector< std::string > &header)
bool is_open () const
void close ()
void write_row (const std::vector< std::string > &fields)

Static Public Member Functions

static std::string escape (const std::string &field)
 quotes a field if it contains a separator, a quote or a line break
template<typename V>
static std::string field (const V &value)
 converts a value to a field. Floats use enough digits to round-trip.

Static Private Member Functions

static std::string format_row (const std::vector< std::string > &fields)

Private Attributes

std::shared_ptr< std::ofstream > out
size_t n_columns = 0

Detailed Description

Minimal RFC 4180 CSV writer used by the run logs.

  • Fields containing a separator, a quote or a line break are quoted, and inner quotes are doubled, so expressions such as Pow(x0,x1) are safe.
  • Files are opened in append mode. The header is written only when the file is new or empty; appending to a file whose header differs throws, instead of silently mixing two schemas in the same file.
  • Every row is flushed, so logs are usable while (or after a crash during) a run.

Definition at line 33 of file csv.h.

Constructor & Destructor Documentation

◆ CsvWriter() [1/2]

Brush::Util::CsvWriter::CsvWriter ( )
default

◆ CsvWriter() [2/2]

Brush::Util::CsvWriter::CsvWriter ( const std::string & path,
const std::vector< std::string > & header )
inline

Definition at line 38 of file csv.h.

Here is the call graph for this function:

Member Function Documentation

◆ close()

void Brush::Util::CsvWriter::close ( )
inline

Definition at line 74 of file csv.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escape()

std::string Brush::Util::CsvWriter::escape ( const std::string & field)
inlinestatic

quotes a field if it contains a separator, a quote or a line break

Definition at line 95 of file csv.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ field()

template<typename V>
std::string Brush::Util::CsvWriter::field ( const V & value)
inlinestatic

converts a value to a field. Floats use enough digits to round-trip.

Definition at line 113 of file csv.h.

Here is the caller graph for this function:

◆ format_row()

std::string Brush::Util::CsvWriter::format_row ( const std::vector< std::string > & fields)
inlinestaticprivate

Definition at line 134 of file csv.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_open()

bool Brush::Util::CsvWriter::is_open ( ) const
inline

Definition at line 72 of file csv.h.

Here is the caller graph for this function:

◆ open()

void Brush::Util::CsvWriter::open ( const std::string & path,
const std::vector< std::string > & header )
inline

Definition at line 43 of file csv.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_row()

void Brush::Util::CsvWriter::write_row ( const std::vector< std::string > & fields)
inline

Definition at line 81 of file csv.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ n_columns

size_t Brush::Util::CsvWriter::n_columns = 0
private

Definition at line 148 of file csv.h.

◆ out

std::shared_ptr<std::ofstream> Brush::Util::CsvWriter::out
private

Definition at line 147 of file csv.h.


The documentation for this class was generated from the following file: