1#ifndef BITSIM_UTILS_IO_CSV_FILE_WRITER_H
2#define BITSIM_UTILS_IO_CSV_FILE_WRITER_H
7#include <initializer_list>
55 template <
typename T>
void write_row(
const std::vector<T> &vals);
70 template <
typename... T>
void write_row(
const std::tuple<T...> &row);
94 throw std::logic_error(
"File " + this->
file_name_ +
" is not open");
98 for (
uint_t c = 0; c < vals.size(); ++c)
103 if (c == vals.size() - 1)
119 throw std::logic_error(
"File " + this->
file_name_ +
" is not open");
123 for (
uint_t c = 0; c < static_cast<uint_t>(vals.size()); ++c)
128 if (c ==
static_cast<uint_t>(vals.size()) - 1)
144 throw std::logic_error(
"File " + this->
file_name_ +
" is not open");
148 for (
uint_t c = 0; c < vals.size(); ++c)
150 f << vals[c] << std::endl;
158 std::apply([&](
auto &&...args) { ((f << args <<
","), ...); }, row);
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
char get_delimiter() const noexcept
Returns the column delimiter.
Definition csv_file_writer.h:80
void write_column_vector(const std::vector< T > &vals)
Write the given vector as a column.
Definition csv_file_writer.h:139
void write_row(const std::vector< T > &vals)
Write a row of the file.
Definition csv_file_writer.h:89
static char default_delimiter()
The default column delimiter.
Definition csv_file_writer.h:28
void write_column_names(const std::vector< std::string > &col_names, bool write_header=true)
Write the column names.
Definition csv_file_writer.cpp:16
CSVWriter(const std::string &filename, char delim=CSVWriter::default_delimiter())
Constructor.
Definition csv_file_writer.cpp:10
void set_delimiter(char delim) noexcept
Set the delimiter.
Definition csv_file_writer.h:75
std::string file_name_
Definition file_handler_base.h:162
bool is_open() const noexcept
Definition file_handler_base.h:113
handler_type & get_file_stream() noexcept
Definition file_handler_base.h:85
virtual void write_header()
Write the header of the file. By default some information such as date and time the file was created ...
Definition file_writer_base.cpp:59
FileWriterBase()=default
Default ctor.
Definition csv_file_reader.cpp:12
Definition bitsim_utils.h:11
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Eigen::RowVectorX< T > DynVec
Dynamically sized row vector.
Definition bitsim_types.h:101