#include <CSVWriter.h>
|
using | serializable_types = std::variant< size_t, int, double, std::string > |
| The types that can be written to the CSV file. More...
|
|
Definition at line 30 of file CSVWriter.h.
◆ serializable_types
The types that can be written to the CSV file.
Definition at line 35 of file CSVWriter.h.
◆ CSVWriter() [1/4]
CSVWriter::CSVWriter |
( |
std::filesystem::path |
file_path, |
|
|
const std::vector< std::string > & |
headers, |
|
|
bool |
append, |
|
|
std::string |
separator = ";" |
|
) |
| |
Creates a new CSVWriter instance.
- Parameters
-
file_path | The path to the CSV file to write to. |
headers | The headers of the CSV file. |
append | Whether to append to the CSV file or overwrite it. |
separator | The separator to use between values. |
Definition at line 17 of file CSVWriter.cpp.
std::string separator
The separator to use between values.
void initialize(const std::vector< std::string > &headers)
Initializes the CSV file and writes the header row.
bool append
Whether to append to the CSV file or overwrite it.
std::vector< std::string > headers
The headers of the CSV file.
std::filesystem::path file_path
The path to the CSV file to write to.
◆ CSVWriter() [2/4]
CSVWriter::CSVWriter |
( |
std::filesystem::path |
file_path, |
|
|
bool |
append, |
|
|
std::string |
separator = ";" |
|
) |
| |
|
explicit |
Creates a new CSVWriter instance.
- Parameters
-
file_path | The path to the CSV file to write to. |
append | Whether to append to the CSV file or overwrite it. |
separator | The separator to use between values. |
Definition at line 21 of file CSVWriter.cpp.
◆ CSVWriter() [3/4]
◆ CSVWriter() [4/4]
Definition at line 24 of file CSVWriter.cpp.
std::ofstream file
The file stream to write to.
◆ ~CSVWriter()
CSVWriter::~CSVWriter |
( |
| ) |
|
Definition at line 38 of file CSVWriter.cpp.
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
◆ initialize()
void CSVWriter::initialize |
( |
const std::vector< std::string > & |
headers | ) |
|
Initializes the CSV file and writes the header row.
- Parameters
-
headers | The headers of the CSV file. |
Definition at line 43 of file CSVWriter.cpp.
48 if (!std::filesystem::exists(
file_path)) {
49 std::filesystem::create_directories(
file_path.parent_path());
60 if (!
file.is_open()) {
62 throw std::runtime_error(
"Could not open file for writing!");
void writeRow(const std::vector< serializable_types > &row)
Writes a row to the CSV file.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ writeRow()
Writes a row to the CSV file.
- Parameters
-
Definition at line 70 of file CSVWriter.cpp.
71 if (row.size() !=
headers.size()) {
73 throw std::runtime_error(
"Row size does not match cols size!");
76 for (
size_t i = 0; i < row.size(); i++) {
void write_csv_element(std::ofstream &file, const T &value)
Writes a single element to the CSV file.
◆ append
Whether to append to the CSV file or overwrite it.
Definition at line 94 of file CSVWriter.h.
◆ file
std::ofstream CSVWriter::file |
|
private |
The file stream to write to.
Definition at line 84 of file CSVWriter.h.
◆ file_path
std::filesystem::path CSVWriter::file_path |
|
private |
The path to the CSV file to write to.
Definition at line 89 of file CSVWriter.h.
◆ headers
std::vector<std::string> CSVWriter::headers |
|
private |
The headers of the CSV file.
Definition at line 99 of file CSVWriter.h.
◆ separator
std::string CSVWriter::separator |
|
private |
The separator to use between values.
Definition at line 104 of file CSVWriter.h.
The documentation for this class was generated from the following files: