|
Vince's CSV Parser
|
Main class for parsing CSVs from files and in-memory sources. More...
#include <csv_reader.hpp>
Classes | |
| class | iterator |
| An input iterator capable of handling large files. More... | |
Public Member Functions | |
| CSVReader (const CSVReader &)=delete | |
| CSVReader (CSVReader &&)=default | |
| CSVReader & | operator= (const CSVReader &)=delete |
| CSVReader & | operator= (CSVReader &&other)=default |
Constructors | |
Constructors for iterating over large files and parsing in-memory sources. | |
| CSVReader (csv::string_view filename, CSVFormat format=CSVFormat::guess_csv()) | |
| Reads an arbitrarily large CSV file using memory-mapped IO. More... | |
| template<typename TStream , csv::enable_if_t< std::is_base_of< std::istream, TStream >::value, int > = 0> | |
| CSVReader (TStream &source, CSVFormat format=CSVFormat()) | |
Allows parsing stream sources such as std::stringstream or std::ifstream More... | |
Retrieving CSV Rows | |
| bool | read_row (CSVRow &row) |
| Retrieve rows as CSVRow objects, returning true if more rows are available. More... | |
| iterator | begin () |
| Return an iterator to the first row in the reader. | |
| HEDLEY_CONST iterator | end () const noexcept |
| A placeholder for the imaginary past the end row in a CSV. More... | |
| bool | eof () const noexcept |
| Returns true if we have reached end of file. | |
CSV Metadata | |
| CSVFormat | get_format () const |
| Return the format of the original raw CSV. | |
| std::vector< std::string > | get_col_names () const |
| Return the CSV's column names as a vector of strings. | |
| int | index_of (csv::string_view col_name) const |
| Return the index of the column name if found or csv::CSV_NOT_FOUND otherwise. | |
CSV Metadata: Attributes | |
| CONSTEXPR bool | empty () const noexcept |
| Whether or not the file or stream contains valid CSV rows, not including the header. More... | |
| CONSTEXPR size_t | n_rows () const noexcept |
| Retrieves the number of rows that have been read so far. | |
| bool | utf8_bom () const noexcept |
| Whether or not CSV was prefixed with a UTF-8 bom. | |
Protected Member Functions | |
| void | set_col_names (const std::vector< std::string > &) |
| Sets this reader's column names and associated data. More... | |
Multi-Threaded File Reading Functions | |
| bool | read_csv (size_t bytes=internals::ITERATION_CHUNK_SIZE) |
| Read a chunk of CSV data. More... | |
Protected Attributes | |
CSV Settings | |
| CSVFormat | _format |
Parser State | |
| internals::ColNamesPtr | col_names = std::make_shared<internals::ColNames>() |
| Pointer to a object containing column information. | |
| std::unique_ptr< internals::IBasicCSVParser > | parser = nullptr |
| Helper class which actually does the parsing. | |
| std::unique_ptr< RowCollection > | records {new RowCollection(100)} |
| Queue of parsed CSV rows. | |
| size_t | n_cols = 0 |
| The number of columns in this CSV. | |
| size_t | _n_rows = 0 |
| How many rows (minus header) have been read so far. | |
Main class for parsing CSVs from files and in-memory sources.
All rows are compared to the column names for length consistency
Definition at line 57 of file csv_reader.hpp.
| csv::CSVReader::CSVReader | ( | csv::string_view | filename, |
| CSVFormat | format = CSVFormat::guess_csv() |
||
| ) |
Reads an arbitrarily large CSV file using memory-mapped IO.
Details: Reads the first block of a CSV file synchronously to get information such as column names and delimiting character.
| [in] | filename | Path to CSV file |
| [in] | format | Format of the CSV file |
Guess delimiter and header row
Definition at line 154 of file csv_reader.cpp.
|
inline |
Allows parsing stream sources such as std::stringstream or std::ifstream
| TStream | An input stream deriving from std::istream |
Definition at line 120 of file csv_reader.hpp.
|
inlinenoexcept |
Whether or not the file or stream contains valid CSV rows, not including the header.
Definition at line 167 of file csv_reader.hpp.
|
noexcept |
A placeholder for the imaginary past the end row in a CSV.
Attempting to deference this will lead to bad things.
Definition at line 26 of file csv_reader_iterator.cpp.
| bool csv::CSVReader::read_row | ( | CSVRow & | row | ) |
Retrieve rows as CSVRow objects, returning true if more rows are available.
| [out] | row | The variable where the parsed row will be stored |
Example:
Definition at line 272 of file csv_reader.cpp.