/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/csv.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/csv.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
csv.hh
Go to the documentation of this file.
1#pragma once
2
3// standard library
4#include <iosfwd>
5#include <string>
6#include <string_view>
7#include <vector>
8
9namespace DiFfRG
10{
24 struct CsvDialect {
26 char separator = ',';
28 bool has_header = false;
30 char comment = '#';
31 };
32
39 struct CsvTable {
41 std::vector<std::string> header;
43 std::vector<std::vector<double>> columns;
44
45 size_t n_rows() const;
46 size_t n_cols() const;
47
56 size_t column_index(std::string_view name) const;
57 };
58
66 CsvTable read_csv(const std::string &path, const CsvDialect &dialect = {});
67
75 CsvTable parse_csv(std::string_view content, const CsvDialect &dialect = {}, std::string_view origin = {});
76
83 std::vector<std::string> split_csv_line(std::string_view line, char separator);
84
88 double parse_csv_cell(std::string_view field);
89
93 void write_csv_header(std::ostream &stream, const std::vector<std::string> &names, const CsvDialect &dialect = {});
94
98 void write_csv_row(std::ostream &stream, const std::vector<double> &values, const CsvDialect &dialect = {});
99} // namespace DiFfRG
Definition complex_math.hh:10
double parse_csv_cell(std::string_view field)
Parse a single numeric cell, yielding NaN for anything that is not a number.
void write_csv_row(std::ostream &stream, const std::vector< double > &values, const CsvDialect &dialect={})
Write one row of values.
CsvTable parse_csv(std::string_view content, const CsvDialect &dialect={}, std::string_view origin={})
Parse CSV held in memory into a numeric table.
std::vector< std::string > split_csv_line(std::string_view line, char separator)
Split one CSV line into its fields, honouring quoting.
CsvTable read_csv(const std::string &path, const CsvDialect &dialect={})
Read a CSV file into a numeric table.
void write_csv_header(std::ostream &stream, const std::vector< std::string > &names, const CsvDialect &dialect={})
Write a header row, quoting any name that would otherwise forge a field boundary.
The CSV dialect DiFfRG reads and writes.
Definition csv.hh:24
bool has_header
Definition csv.hh:28
char comment
Definition csv.hh:30
char separator
Definition csv.hh:26
A numeric table, stored one vector per column.
Definition csv.hh:39
size_t n_rows() const
size_t column_index(std::string_view name) const
Look up a column by name.
std::vector< std::string > header
Definition csv.hh:41
size_t n_cols() const
std::vector< std::vector< double > > columns
Definition csv.hh:43