|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Lazy CSV reader for large files. More...
#include <parse-csv.H>
Classes | |
| class | Iterator |
Public Member Functions | |
| CsvReader (const std::string &filename, char delimiter=',') | |
| Construct reader from file path. | |
| CsvReader (std::istream &stream, char delimiter=',') | |
| Construct reader from stream. | |
| CsvReader (CsvReader &&other) | |
| Take the stream and the header of another reader, which is left reading nothing. | |
| CsvReader & | operator= (CsvReader &&other) |
| Exchange this reader with another, which is left with the previous stream and header of this one. | |
| void | swap (CsvReader &other) |
| Exchange the streams, the headers and the counters of this reader and another. | |
| Array< std::string > | read_header () |
| Read and store the header row. | |
| bool | has_next () const |
| Check if more rows are available. | |
| Array< std::string > | next () |
| Read the next row as Array. | |
| CsvRow | next_row () |
| Read the next row with header access. | |
| size_t | rows_read () const |
| Get number of rows read so far. | |
| const Array< std::string > & | header () const |
| Get the header (if read). | |
| bool | has_header () const |
| Check if header was read. | |
| void | skip (size_t n) |
| Skip N rows. | |
| void | reset () |
| Reset to beginning (only works for file-based readers). | |
| Iterator | begin () |
| Iterator | end () |
Private Attributes | |
| std::ifstream | file_ |
| std::istream * | stream_ |
| bool | owns_stream_ |
| char | delimiter_ |
| Array< std::string > | header_ |
| bool | has_header_ |
| size_t | row_count_ |
Lazy CSV reader for large files.
CsvReader provides an iterator-based interface for reading CSV files row by row without loading the entire file into memory.
Definition at line 711 of file parse-csv.H.
|
inlineexplicit |
Construct reader from file path.
| std::runtime_error | If file cannot be opened. |
Definition at line 724 of file parse-csv.H.
References file_.
|
inlineexplicit |
Construct reader from stream.
Definition at line 733 of file parse-csv.H.
|
inline |
Take the stream and the header of another reader, which is left reading nothing.
The implicit move took the file but copied the pointer to it: the reader read through the file member of the moved-from reader, also after that reader was destroyed.
| [in,out] | other | reader to move from. |
Definition at line 746 of file parse-csv.H.
|
inline |
Definition at line 878 of file parse-csv.H.
|
inline |
Definition at line 879 of file parse-csv.H.
|
inline |
Check if header was read.
Definition at line 822 of file parse-csv.H.
References has_header_.
Referenced by TEST_F().
|
inline |
Check if more rows are available.
Definition at line 793 of file parse-csv.H.
References Aleph::and, and stream_.
Referenced by Aleph::CsvReader::Iterator::Iterator(), main(), Aleph::CsvReader::Iterator::operator++(), skip(), TEST(), TEST(), and TEST_F().
|
inline |
Get the header (if read).
Definition at line 819 of file parse-csv.H.
References header_.
Referenced by TEST_F().
|
inline |
Read the next row as Array.
Definition at line 799 of file parse-csv.H.
References Aleph::csv_read_row(), delimiter_, row_count_, and stream_.
Referenced by Aleph::CsvReader::Iterator::Iterator(), Aleph::CsvReader::Iterator::operator++(), skip(), TEST(), TEST(), TEST_F(), and TEST_F().
|
inline |
Read the next row with header access.
Definition at line 806 of file parse-csv.H.
References Aleph::csv_read_row(), delimiter_, has_header_, header_, row_count_, and stream_.
Exchange this reader with another, which is left with the previous stream and header of this one.
| [in,out] | other | reader to move from. |
Definition at line 758 of file parse-csv.H.
References swap().
|
inline |
Read and store the header row.
Definition at line 785 of file parse-csv.H.
References Aleph::csv_read_row(), delimiter_, has_header_, header_, and stream_.
Referenced by main(), reset(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Reset to beginning (only works for file-based readers).
Definition at line 832 of file parse-csv.H.
References file_, has_header_, owns_stream_, read_header(), and row_count_.
Referenced by TEST().
|
inline |
Get number of rows read so far.
Definition at line 816 of file parse-csv.H.
References row_count_.
Referenced by TEST_F().
|
inline |
Skip N rows.
Definition at line 825 of file parse-csv.H.
References Aleph::and, has_next(), and next().
Referenced by TEST_F().
|
inline |
Exchange the streams, the headers and the counters of this reader and another.
| [in,out] | other | reader to exchange with. |
Definition at line 768 of file parse-csv.H.
References delimiter_, file_, has_header_, header_, owns_stream_, row_count_, stream_, and Aleph::Array< T >::swap().
Referenced by operator=().
|
private |
Definition at line 716 of file parse-csv.H.
Referenced by next(), next_row(), read_header(), and swap().
|
private |
Definition at line 713 of file parse-csv.H.
Referenced by CsvReader(), reset(), and swap().
|
private |
Definition at line 718 of file parse-csv.H.
Referenced by has_header(), next_row(), read_header(), reset(), and swap().
|
private |
Definition at line 717 of file parse-csv.H.
Referenced by header(), next_row(), read_header(), and swap().
|
private |
Definition at line 715 of file parse-csv.H.
|
private |
Definition at line 719 of file parse-csv.H.
Referenced by next(), next_row(), reset(), rows_read(), and swap().
|
private |
Definition at line 714 of file parse-csv.H.
Referenced by has_next(), next(), next_row(), read_header(), and swap().