16template <std::
floating_po
int F>
19 std::array<char, bufmaxsize + 1>
s;
22 static constexpr char end =
'\n';
24 [[nodiscard]] F
read(std::istream &is,
char sep) {
28 throw read_error(
"csv::read_row extraction failed: " +
29 std::to_string(is.bad()) +
" " +
30 std::to_string(is.fail()) +
" " +
31 std::to_string(is.eof()));
38 char *bufend =
s.data() +
bufidx;
41 if (ptr != bufend && *ptr != sep)
42 throw read_error(
"csv::read_row unexpected character '" +
43 std::string{*ptr} +
"'");
46 std::copy(ptr + 1,
static_cast<const char *
>(bufend),
s.data());
55 static const char *
read_single(
const char *bufbegin,
const char *bufend,
57 if (bufbegin != bufend && *bufbegin ==
'+')
59 const auto [ptr, ec] = std::from_chars(bufbegin, bufend, v);
60 const auto bufvw = std::string_view(bufbegin, bufend);
61 if (ec != std::errc{})
62 throw read_error(
"csv::read_row conversion failed '" +
64 "': " + std::make_error_code(ec).message());
68 static void strtod_ovl(
const char *str,
char **str_end,
float &v) {
69 v = std::strtof(str, str_end);
71 static void strtod_ovl(
const char *str,
char **str_end,
double &v) {
72 v = std::strtod(str, str_end);
74 static void strtod_ovl(
const char *str,
char **str_end,
long double &v) {
75 v = std::strtold(str, str_end);
77 static const char *
read_single(
const char *bufbegin,
char *bufend, F &v) {
82 if (errno || ptr == bufbegin)
83 throw read_error(
"csv::read_row conversion failed '" +
84 std::string(bufbegin) +
85 "': " + std::to_string(errno));
91 if (
bufidx > 0 || (is.get() !=
end && is))
92 throw read_error(
"csv::read_row line not fully consumed");
95 [[nodiscard]]
bool done(std::istream &is)
const {
101template <std::
floating_po
int F>
106 vv = reader.
read(is, sep);
110template <std::
floating_po
int F>
114 while (!reader.
done(is))
115 v.push_back(reader.
read(is, sep));
std::vector< F > read_row_std_vector(std::istream &is, char sep)
void read_row_impl(std::istream &is, Eigen::Ref< Eigen::VectorX< F > > v, char sep)
static constexpr std::streamsize bufmaxsize
static const char * read_single(const char *bufbegin, char *bufend, F &v)
bool done(std::istream &is) const
std::array< char, bufmaxsize+1 > s
F read(std::istream &is, char sep)
static constexpr char end
static void strtod_ovl(const char *str, char **str_end, double &v)
static void strtod_ovl(const char *str, char **str_end, long double &v)
static void strtod_ovl(const char *str, char **str_end, float &v)
void check_end(std::istream &is) const