15 #ifndef PAAL_READ_ROWS_HPP
16 #define PAAL_READ_ROWS_HPP
21 #include <boost/range/size.hpp>
22 #include <boost/range/algorithm/copy.hpp>
23 #include <boost/range/istream_range.hpp>
45 template <
typename CoordinateType,
46 typename RowType = std::vector<CoordinateType>,
49 std::vector<RowType> &rows,
51 std::size_t max_rows_to_read,
52 ShouldIgnoreBadRow &&should_ignore_bad_row = ShouldIgnoreBadRow{}) {
56 row.reserve(row_size);
58 while ((max_rows_to_read--) && std::getline(input_stream, line)) {
60 std::stringstream row_stream(line);
62 boost::copy(boost::istream_range<CoordinateType>(row_stream), std::back_inserter(row));
64 if((!row_stream.bad() && row_size == boost::size(row)) || !should_ignore_bad_row(line)) {
65 rows.emplace_back(row);
83 template <
typename CoordinateType,
84 typename RowType = std::vector<CoordinateType>,
88 std::vector<RowType> &rows,
89 std::size_t max_rows_to_read,
90 ShouldIgnoreBadRow &&should_ignore_bad_row = ShouldIgnoreBadRow{},
91 FailureMessage &&failure_message = FailureMessage{}) {
92 if(!input_stream.good()) {
93 failure_message(
"Input stream is broken");
99 failure_message(
"Empty input data");
101 std::size_t
const row_size = boost::size(rows.front());
103 failure_message(
"Empty first row");
106 read_rows<CoordinateType>(input_stream, rows, row_size, max_rows_to_read - 1, std::forward<ShouldIgnoreBadRow>(should_ignore_bad_row));
void read_rows_first_row_size(std::istream &input_stream, std::vector< RowType > &rows, std::size_t max_rows_to_read, ShouldIgnoreBadRow &&should_ignore_bad_row=ShouldIgnoreBadRow{}, FailureMessage &&failure_message=FailureMessage{})
reads up to max_rows_to_read rows, size is determine by first row
void read_rows(std::istream &input_stream, std::vector< RowType > &rows, std::size_t row_size, std::size_t max_rows_to_read, ShouldIgnoreBadRow &&should_ignore_bad_row=ShouldIgnoreBadRow{})
reads up to max_rows_to_read rows of size row_size
This file contains set of simple useful functors or functor adapters.
Functor prints failure message.