bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
bitrl::utils::io::CSVWriter Class Reference

The CSVWriter class. Handles writing into CSV file format. More...

#include <csv_file_writer.h>

Inheritance diagram for bitrl::utils::io::CSVWriter:
Collaboration diagram for bitrl::utils::io::CSVWriter:

Public Member Functions

 CSVWriter (const std::string &filename, char delim=CSVWriter::default_delimiter())
 Constructor.
 
void write_column_names (const std::vector< std::string > &col_names, bool write_header=true)
 Write the column names.
 
void write_column_names (const std::vector< std::string_view > &col_names, bool write_header=true)
 Write the column names.
 
void write_column_names (const std::initializer_list< std::string_view > &col_names, bool write_header=true)
 Write the column names.
 
template<typename T >
void write_row (const std::vector< T > &vals)
 Write a row of the file.
 
template<typename T >
void write_row (const DynVec< T > &vals)
 Write the given Vec as a row.
 
template<typename T >
void write_column_vector (const std::vector< T > &vals)
 Write the given vector as a column.
 
template<typename... T>
void write_row (const std::tuple< T... > &row)
 Write the given tuple as a row.
 
void set_delimiter (char delim) noexcept
 Set the delimiter.
 
char get_delimiter () const noexcept
 Returns the column delimiter.
 
- Public Member Functions inherited from bitrl::utils::io::FileWriterBase
 FileWriterBase ()=default
 Default ctor.
 
 FileWriterBase (const std::string &file_name, FileFormats::Type t)
 Constructor. Construct by passing the name of the file to write into.
 
virtual ~FileWriterBase ()
 Destructor.
 
virtual void open () override
 Open the file for writing.
 
char get_comment_mark () const
 Return the mark that signifies the beginning of a comment line.
 
void set_comment_mark (char mark)
 Set the comment mark.
 
virtual void write_header ()
 Write the header of the file. By default some information such as date and time the file was created is written.
 
- Public Member Functions inherited from bitrl::utils::io::FileHandlerBase< std::ofstream >
virtual ~FileHandlerBase ()
 Constructor.
 
FileFormats::Type get_type () const noexcept
 Returns the type of the file.
 
handler_typeget_file_stream () noexcept
 Returns the underlying file stream.
 
const handler_typeget_file_stream () const noexcept
 Returns the underlying file stream.
 
std::string get_filename () const noexcept
 Returns the filename that is used to write.
 
bool is_open () const noexcept
 Return true if and only if the file is open.
 
virtual void close ()
 Close the file. Return true if and only if the file was closed successfully false otherwise.
 

Static Public Member Functions

static char default_delimiter ()
 The default column delimiter.
 
- Static Public Member Functions inherited from bitrl::utils::io::FileWriterBase
static char default_comment_mark ()
 The default comment mark.
 

Additional Inherited Members

- Public Types inherited from bitrl::utils::io::FileHandlerBase< std::ofstream >
typedef std::ofstream handler_type
 
- Protected Member Functions inherited from bitrl::utils::io::FileHandlerBase< std::ofstream >
 FileHandlerBase (const std::string &file_name, FileFormats::Type t)
 protected Constructor so that explicit instantiation of the class fails
 
- Protected Attributes inherited from bitrl::utils::io::FileWriterBase
char comment_mark_
 The mark that signifies the beginning of a comment line. The default is #.
 
- Protected Attributes inherited from bitrl::utils::io::FileHandlerBase< std::ofstream >
std::string file_name_
 The name of the file to write.
 
const FileFormats::Type t_
 The format of the file.
 
handler_type f_
 The low level file handler.
 

Detailed Description

The CSVWriter class. Handles writing into CSV file format.

Constructor & Destructor Documentation

◆ CSVWriter()

bitrl::utils::io::CSVWriter::CSVWriter ( const std::string &  filename,
char  delim = CSVWriter::default_delimiter() 
)

Constructor.

Member Function Documentation

◆ default_delimiter()

static char bitrl::utils::io::CSVWriter::default_delimiter ( )
inlinestatic

The default column delimiter.

◆ get_delimiter()

char bitrl::utils::io::CSVWriter::get_delimiter ( ) const
inlinenoexcept

Returns the column delimiter.

◆ set_delimiter()

void bitrl::utils::io::CSVWriter::set_delimiter ( char  delim)
inlinenoexcept

Set the delimiter.

◆ write_column_names() [1/3]

void bitrl::utils::io::CSVWriter::write_column_names ( const std::initializer_list< std::string_view > &  col_names,
bool  write_header = true 
)

Write the column names.

◆ write_column_names() [2/3]

void bitrl::utils::io::CSVWriter::write_column_names ( const std::vector< std::string > &  col_names,
bool  write_header = true 
)

Write the column names.

◆ write_column_names() [3/3]

void bitrl::utils::io::CSVWriter::write_column_names ( const std::vector< std::string_view > &  col_names,
bool  write_header = true 
)

Write the column names.

◆ write_column_vector()

template<typename T >
void bitrl::utils::io::CSVWriter::write_column_vector ( const std::vector< T > &  vals)

Write the given vector as a column.

◆ write_row() [1/3]

template<typename T >
void bitrl::utils::io::CSVWriter::write_row ( const DynVec< T > &  vals)

Write the given Vec as a row.

◆ write_row() [2/3]

template<typename... T>
void bitrl::utils::io::CSVWriter::write_row ( const std::tuple< T... > &  row)

Write the given tuple as a row.

◆ write_row() [3/3]

template<typename T >
void bitrl::utils::io::CSVWriter::write_row ( const std::vector< T > &  vals)

Write a row of the file.


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