Vince's CSV Parser
Loading...
Searching...
No Matches
csv::CSVRow Class Reference

Data structure for representing CSV rows. More...

#include <csv_row.hpp>

Classes

class  iterator
 Iterator producing short-lived CSVField values with independent lazy conversion caches. More...
 
class  reverse_iterator
 Reverse field-value iterator available since C++11. More...
 

Public Member Functions

 CSVRow (internals::RawCSVDataPtr _data)
 Construct a CSVRow view over parsed row storage.
 
 CSVRow (internals::RawCSVDataPtr _data, size_t _data_start, size_t _field_bounds)
 
 CSVRow (internals::RawCSVDataPtr _data, size_t _data_start, size_t _field_bounds, size_t _row_length)
 
CONSTEXPR bool empty () const noexcept
 Indicates whether row is empty or not.
 
CONSTEXPR size_t size () const noexcept
 Return the number of fields in this row.
 
size_t byte_offset () const noexcept
 Return the absolute byte offset where this row starts in the source.
 
std::unordered_map< std::string, std::string > try_to_unordered_map (CSVError &error) const
 Materialize named values; unknown names or absent header positions report an error.
 
std::unordered_map< std::string, std::string > try_to_unordered_map (CSVError &error, const std::vector< std::string > &subset) const
 
Value Retrieval
CSVField try_field (size_t index, CSVError &error) const
 Checked field retrieval.
 
CSVField try_field (csv::string_view name, CSVError &error) const
 
CSVField operator[] (size_t n) const
 Return the field at n.
 
CSVField operator[] (csv::string_view col_name) const
 Return the field named col_name.
 
std::string try_to_json (const std::vector< std::string > &subset, CSVError &error) const
 Serialize a subset, reporting unknown column names.
 
std::string try_to_json_array (const std::vector< std::string > &subset, CSVError &error) const
 
std::string to_json (const std::vector< std::string > &subset={}) const
 
std::string to_json_array (const std::vector< std::string > &subset={}) const
 
const std::vector< std::string > & get_col_names () const
 Retrieve this row's associated column names.
 
internals::ConstColNamesPtr col_names_ptr () const noexcept
 Internal accessor for preserving resolved column-name lookup policy across helper types.
 
std::unordered_map< std::string, std::string > to_unordered_map () const
 Convert this CSVRow into an unordered map.
 
std::unordered_map< std::string, std::string > to_unordered_map (const std::vector< std::string > &subset) const
 Convert a selected subset of columns into an unordered map.
 
auto to_sv_range () const
 Convert this CSVRow into a std::ranges::input_range of string_views.
 
 operator std::vector< std::string > () const
 Convert this row into a std::vector<std::string>.
 
csv::string_view raw_str () const noexcept
 Return a string_view of the raw bytes of this row as they appear in the underlying parse buffer, up to (but not including) the trailing record terminator.
 
Iterators

Iteration produces field values with independent conversion caches.

iterator begin () const noexcept
 
iterator end () const noexcept
 
reverse_iterator rbegin () const noexcept
 
reverse_iterator rend () const noexcept
 

Friends

template<typename RowSink , typename ParsePolicy , typename FieldPolicy , typename RowPolicy >
class internals::CSVParserCore
 
struct internals::CSVRowRowPolicy
 
struct internals::data_frame::RowViewAccessor
 
struct internals::speculative::CSVRowFragment
 

Detailed Description

Data structure for representing CSV rows.

Definition at line 533 of file csv_row.hpp.

Constructor & Destructor Documentation

◆ CSVRow() [1/3]

csv::CSVRow::CSVRow ( internals::RawCSVDataPtr  _data)
inline

Construct a CSVRow view over parsed row storage.

Definition at line 545 of file csv_row.hpp.

◆ CSVRow() [2/3]

csv::CSVRow::CSVRow ( internals::RawCSVDataPtr  _data,
size_t  _data_start,
size_t  _field_bounds 
)
inline

Definition at line 546 of file csv_row.hpp.

◆ CSVRow() [3/3]

csv::CSVRow::CSVRow ( internals::RawCSVDataPtr  _data,
size_t  _data_start,
size_t  _field_bounds,
size_t  _row_length 
)
inline

Definition at line 548 of file csv_row.hpp.

Member Function Documentation

◆ begin()

CSVRow::iterator csv::CSVRow::begin ( ) const
noexcept

Definition at line 218 of file csv_row.cpp.

◆ byte_offset()

size_t csv::CSVRow::byte_offset ( ) const
inlinenoexcept

Return the absolute byte offset where this row starts in the source.

Definition at line 558 of file csv_row.hpp.

◆ col_names_ptr()

internals::ConstColNamesPtr csv::CSVRow::col_names_ptr ( ) const
inlinenoexcept

Internal accessor for preserving resolved column-name lookup policy across helper types.

Definition at line 624 of file csv_row.hpp.

◆ empty()

CONSTEXPR bool csv::CSVRow::empty ( ) const
inlinenoexcept

Indicates whether row is empty or not.

Definition at line 552 of file csv_row.hpp.

◆ end()

CSVRow::iterator csv::CSVRow::end ( ) const
noexcept

Definition at line 222 of file csv_row.cpp.

◆ get_col_names()

const std::vector< std::string > & csv::CSVRow::get_col_names ( ) const
inline

Retrieve this row's associated column names.

Definition at line 619 of file csv_row.hpp.

◆ operator std::vector< std::string >()

csv::CSVRow::operator std::vector< std::string > ( ) const

Convert this row into a std::vector<std::string>.

This conversion is primarily intended for write-side workflows, such as reordering or selecting columns before forwarding the row to CSVWriter.

Note
This is less efficient than indexed access via operator[] because it materializes all fields as owning strings.

◆ operator[]() [1/2]

CSVField csv::CSVRow::operator[] ( csv::string_view  col_name) const

Return the field named col_name.

Throws std::runtime_error if the name is absent.

Definition at line 37 of file csv_row.cpp.

◆ operator[]() [2/2]

CSVField csv::CSVRow::operator[] ( size_t  n) const

Return the field at n.

Throws std::runtime_error if the index is out of bounds.

Definition at line 30 of file csv_row.cpp.

◆ raw_str()

csv::string_view csv::CSVRow::raw_str ( ) const
noexcept

Return a string_view of the raw bytes of this row as they appear in the underlying parse buffer, up to (but not including) the trailing record terminator.

Warning
The view is only valid for as long as the CSVRow (and its associated data chunk) remains alive.

Definition at line 75 of file csv_row.cpp.

◆ rbegin()

CSVRow::reverse_iterator csv::CSVRow::rbegin ( ) const
noexcept

Definition at line 226 of file csv_row.cpp.

◆ rend()

CSVRow::reverse_iterator csv::CSVRow::rend ( ) const
noexcept

Definition at line 230 of file csv_row.cpp.

◆ size()

CONSTEXPR size_t csv::CSVRow::size ( ) const
inlinenoexcept

Return the number of fields in this row.

Definition at line 555 of file csv_row.hpp.

◆ to_json()

std::string csv::CSVRow::to_json ( const std::vector< std::string > &  subset = {}) const
inline

Definition at line 604 of file csv_row.hpp.

◆ to_json_array()

std::string csv::CSVRow::to_json_array ( const std::vector< std::string > &  subset = {}) const
inline

Definition at line 610 of file csv_row.hpp.

◆ to_sv_range()

auto csv::CSVRow::to_sv_range ( ) const
inline

Convert this CSVRow into a std::ranges::input_range of string_views.

Note
Requires C++20 or later.

Definition at line 647 of file csv_row.hpp.

◆ to_unordered_map() [1/2]

std::unordered_map< std::string, std::string > csv::CSVRow::to_unordered_map ( ) const

Convert this CSVRow into an unordered map.

The keys are the column names and the values are the corresponding field values.

Definition at line 127 of file csv_row.cpp.

◆ to_unordered_map() [2/2]

std::unordered_map< std::string, std::string > csv::CSVRow::to_unordered_map ( const std::vector< std::string > &  subset) const

Convert a selected subset of columns into an unordered map.

Definition at line 134 of file csv_row.cpp.

◆ try_field() [1/2]

CSVField csv::CSVRow::try_field ( csv::string_view  name,
CSVError &  error 
) const

Definition at line 56 of file csv_row.cpp.

◆ try_field() [2/2]

CSVField csv::CSVRow::try_field ( size_t  index,
CSVError &  error 
) const

Checked field retrieval.

Inspect error before using the returned field. The field's view remains valid only while this row's storage is alive.

Definition at line 47 of file csv_row.cpp.

◆ try_to_json()

std::string csv::CSVRow::try_to_json ( const std::vector< std::string > &  subset,
CSVError &  error 
) const
inline

Serialize a subset, reporting unknown column names.

Definition at line 591 of file csv_row.hpp.

◆ try_to_json_array()

std::string csv::CSVRow::try_to_json_array ( const std::vector< std::string > &  subset,
CSVError &  error 
) const
inline

Definition at line 597 of file csv_row.hpp.

◆ try_to_unordered_map() [1/2]

std::unordered_map< std::string, std::string > csv::CSVRow::try_to_unordered_map ( CSVError &  error) const

Materialize named values; unknown names or absent header positions report an error.

Definition at line 93 of file csv_row.cpp.

◆ try_to_unordered_map() [2/2]

std::unordered_map< std::string, std::string > csv::CSVRow::try_to_unordered_map ( CSVError &  error,
const std::vector< std::string > &  subset 
) const

Definition at line 97 of file csv_row.cpp.

Friends And Related Symbol Documentation

◆ internals::CSVParserCore

template<typename RowSink , typename ParsePolicy , typename FieldPolicy , typename RowPolicy >
friend class internals::CSVParserCore
friend

Definition at line 536 of file csv_row.hpp.

◆ internals::CSVRowRowPolicy

friend struct internals::CSVRowRowPolicy
friend

Definition at line 537 of file csv_row.hpp.

◆ internals::data_frame::RowViewAccessor

friend struct internals::data_frame::RowViewAccessor
friend

Definition at line 538 of file csv_row.hpp.

◆ internals::speculative::CSVRowFragment

friend struct internals::speculative::CSVRowFragment
friend

Definition at line 540 of file csv_row.hpp.


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