Vince's CSV Parser
csv_reader_iterator.cpp
Go to the documentation of this file.
1 
5 #include "csv_reader.hpp"
6 
7 namespace csv {
10  if (this->records->empty()) {
11  this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE);
12  this->read_csv_worker.join();
13 
14  // Still empty => return end iterator
15  if (this->records->empty()) return this->end();
16  }
17 
18  this->_n_rows++;
19  CSVReader::iterator ret(this, this->records->pop_front());
20  return ret;
21  }
22 
26  CSV_INLINE HEDLEY_CONST CSVReader::iterator CSVReader::end() const noexcept {
27  return CSVReader::iterator();
28  }
29 
31  // CSVReader::iterator //
33 
34  CSV_INLINE CSVReader::iterator::iterator(CSVReader* _daddy, CSVRow&& _row) :
35  daddy(_daddy) {
36  row = std::move(_row);
37  }
38 
47  if (!daddy->read_row(this->row)) {
48  this->daddy = nullptr; // this == end()
49  }
50 
51  return *this;
52  }
53 
56  auto temp = *this;
57  if (!daddy->read_row(this->row)) {
58  this->daddy = nullptr; // this == end()
59  }
60 
61  return temp;
62  }
63 }
An input iterator capable of handling large files.
Definition: csv_reader.hpp:69
iterator & operator++()
Pre-increment iterator.
Main class for parsing CSVs from files and in-memory sources.
Definition: csv_reader.hpp:57
HEDLEY_CONST iterator end() const noexcept
A placeholder for the imaginary past the end row in a CSV.
bool read_row(CSVRow &row)
Retrieve rows as CSVRow objects, returning true if more rows are available.
Definition: csv_reader.cpp:272
iterator begin()
Return an iterator to the first row in the reader.
Data structure for representing CSV rows.
Definition: csv_row.hpp:304
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Definition: common.hpp:26
Defines functionality needed for basic CSV parsing.
std::unique_ptr< RowCollection > records
Queue of parsed CSV rows.
Definition: csv_reader.hpp:201
size_t _n_rows
How many rows (minus header) have been read so far.
Definition: csv_reader.hpp:204
bool read_csv(size_t bytes=internals::ITERATION_CHUNK_SIZE)
Read a chunk of CSV data.
Definition: csv_reader.cpp:241
constexpr size_t ITERATION_CHUNK_SIZE
For functions that lazy load a large CSV, this determines how many bytes are read at a time.
Definition: common.hpp:151
The all encompassing namespace.