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  CSVReader::iterator ret(this, this->records->pop_front());
19  return ret;
20  }
21 
25  CSV_INLINE HEDLEY_CONST CSVReader::iterator CSVReader::end() const noexcept {
26  return CSVReader::iterator();
27  }
28 
30  // CSVReader::iterator //
32 
33  CSV_INLINE CSVReader::iterator::iterator(CSVReader* _daddy, CSVRow&& _row) :
34  daddy(_daddy) {
35  row = std::move(_row);
36  }
37 
46  if (!daddy->read_row(this->row)) {
47  this->daddy = nullptr; // this == end()
48  }
49 
50  return *this;
51  }
52 
55  auto temp = *this;
56  if (!daddy->read_row(this->row)) {
57  this->daddy = nullptr; // this == end()
58  }
59 
60  return temp;
61  }
62 }
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:296
#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:202
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.