Vince's CSV Parser
Loading...
Searching...
No Matches
csv::internals::StreamParser< TStream > Class Template Reference

A class for parsing CSV data from any std::istream, including non-seekable sources such as pipes and decompression filters. More...

#include <basic_csv_parser.hpp>

Inherits csv::internals::IBasicCSVParser.

Public Member Functions

 StreamParser (TStream &source, const CSVFormat &format, const ColNamesPtr &col_names=nullptr)
 
 StreamParser (TStream &source, internals::ParseFlagMap parse_flags, internals::WhitespaceMap ws_flags)
 
std::string & get_csv_head () override
 
void next (size_t bytes=CSV_CHUNK_SIZE_DEFAULT) override
 Parse the next block of data.
 
- Public Member Functions inherited from csv::internals::IBasicCSVParser
 IBasicCSVParser (const CSVFormat &, const ColNamesPtr &)
 
 IBasicCSVParser (const ParseFlagMap &parse_flags, const WhitespaceMap &ws_flags)
 
bool eof ()
 Whether or not we have reached the end of source.
 
ResolvedFormat get_resolved_format ()
 
void end_feed ()
 Indicate the last block of data has been parsed.
 
CONSTEXPR_17 ParseFlags parse_flag (const char ch) const noexcept
 
CONSTEXPR_17 ParseFlags compound_parse_flag (const char ch) const noexcept
 
CONSTEXPR bool utf8_bom () const
 Whether or not this CSV has a UTF-8 byte order mark.
 
void set_output (RowCollection &rows)
 

Additional Inherited Members

- Protected Member Functions inherited from csv::internals::IBasicCSVParser
CONSTEXPR bool no_chunk () const
 Whether or not source needs to be read in chunks.
 
size_t parse ()
 Parse the current chunk of data and return the completed-row prefix length.
 
void reset_data_ptr ()
 Create a new RawCSVDataPtr for a new chunk of data.
 
void resolve_format_from_head (const CSVFormat &format)
 
- Protected Attributes inherited from csv::internals::IBasicCSVParser
CSVRow current_row_
 
RawCSVDataPtr data_ptr_ = nullptr
 
ColNamesPtr col_names_ = nullptr
 
RawCSVFieldListfields_ = nullptr
 
int field_start_ = UNINITIALIZED_FIELD
 
size_t field_length_ = 0
 
SentinelVecs simd_sentinels_
 Precomputed SIMD broadcast vectors for find_next_non_special.
 
ParseFlagMap parse_flags_
 An array where the (i + 128)th slot gives the ParseFlags for ASCII character i.
 
bool eof_ = false
 
ResolvedFormat format
 
size_t source_size_ = 0
 The size of the incoming CSV.
 

Detailed Description

template<typename TStream>
class csv::internals::StreamParser< TStream >

A class for parsing CSV data from any std::istream, including non-seekable sources such as pipes and decompression filters.

Chunk boundary handling
parse() returns the byte offset of the start of the last incomplete row in the current chunk (the "remainder"). Rather than seeking back to re-read those bytes (which requires a seekable stream), they are saved in leftover_ and prepended to the next chunk. This is semantically identical to the old seek-back approach but works on any istream and avoids the syscall overhead of seekg().
Format resolution
The constructor reads a head buffer from the stream via get_csv_head() and passes it to resolve_format_from_head(), which infers the delimiter and header row when not explicitly set. The head bytes are stored in leftover_ so the first next() call re-parses them without re-reading.

Definition at line 316 of file basic_csv_parser.hpp.

Constructor & Destructor Documentation

◆ StreamParser() [1/2]

template<typename TStream >
csv::internals::StreamParser< TStream >::StreamParser ( TStream source,
const CSVFormat format,
const ColNamesPtr &  col_names = nullptr 
)
inline

Definition at line 320 of file basic_csv_parser.hpp.

◆ StreamParser() [2/2]

template<typename TStream >
csv::internals::StreamParser< TStream >::StreamParser ( TStream source,
internals::ParseFlagMap  parse_flags,
internals::WhitespaceMap  ws_flags 
)
inline

Definition at line 328 of file basic_csv_parser.hpp.

◆ ~StreamParser()

Definition at line 336 of file basic_csv_parser.hpp.

Member Function Documentation

◆ get_csv_head()

template<typename TStream >
std::string & csv::internals::StreamParser< TStream >::get_csv_head ( )
inlineoverridevirtual

Implements csv::internals::IBasicCSVParser.

Definition at line 338 of file basic_csv_parser.hpp.

◆ next()

template<typename TStream >
void csv::internals::StreamParser< TStream >::next ( size_t  bytes = CSV_CHUNK_SIZE_DEFAULT)
inlineoverridevirtual

Parse the next block of data.

Implements csv::internals::IBasicCSVParser.

Definition at line 343 of file basic_csv_parser.hpp.


The documentation for this class was generated from the following file: