17 requires(std::floating_point<F> || std::integral<F>)
19 static constexpr std::streamsize bufmaxsize = 64;
20 std::array<char, bufmaxsize + 1>
s;
21 std::streamsize bufidx = 0;
22 bool keep_reading =
true;
23 static constexpr char end =
'\n';
31 char *
bufend = s.data() + bufidx;
32 const char *ptr = read_single(s.data(),
bufend,
v);
34 if (ptr !=
bufend && *ptr != sep)
35 throw read_error(
"csv::read_row unexpected character '" +
36 std::string{*ptr} +
"'");
39 std::copy(ptr + 1,
static_cast<const char *
>(
bufend), s.data());
40 bufidx -= ptr + 1 - s.data();
50 "csv::read_row invalid stream: " + std::to_string(
is.bad()) +
51 " " + std::to_string(
is.fail()) +
" " +
52 std::to_string(
is.eof()));
53 if (bufmaxsize == bufidx)
55 if (!
is.get(s.data() + bufidx, bufmaxsize - bufidx + 1, end))
57 "csv::read_row extraction failed: " + std::to_string(
is.bad()) +
58 " " + std::to_string(
is.fail()) +
" " +
59 std::to_string(
is.eof()));
60 bufidx +=
is.gcount();
61 keep_reading =
is.peek() != end && !
is.eof();
62 assert(bufidx <= bufmaxsize);
67 if (
is.eof() ||
is.peek() == end)
71 if (bufidx == 0 || s.front() !=
'#')
73 while (keep_reading) {
83 static const char *read_single(
const char *
bufbegin,
const char *
bufend,
89 if (
ec != std::errc{})
90 throw read_error(
"csv::read_row conversion failed '" +
92 "': " + std::make_error_code(
ec).message());
112 v =
static_cast<int>(std::strtol(
str,
str_end, 10));
120 throw read_error(
"csv::read_row conversion failed '" +
122 "': " + std::to_string(
errno));
128 if (bufidx > 0 || (!
is.eof() &&
is.get() != end))
129 throw read_error(
"csv::read_row line not fully consumed");
133 bool keep_reading =
is.peek() != end && !
is.eof();
134 return bufidx == 0 && !keep_reading;
138#ifdef ALPAQA_WITH_QUAD_PRECISION
151 requires(std::floating_point<F> || std::integral<F>)
162 requires(std::floating_point<F> || std::integral<F>)
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)
void read_chunk(std::istream &is)
static void strtod_ovl(const char *str, char **str_end, long &v)
static void strtod_ovl(const char *str, char **str_end, int &v)
static const char * read_single(const char *bufbegin, char *bufend, F &v)
bool done(std::istream &is) const
std::array< char, bufmaxsize+1 > s
static void strtod_ovl(const char *str, char **str_end, long long &v)
void next_line(std::istream &is) const
F read(std::istream &is, char sep)
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 skip_comments(std::istream &is)