Vince's CSV Parser
csv::CSVRow Class Reference

Data structure for representing CSV rows. More...

#include <csv_row.hpp>

Classes

class  iterator
 A random access iterator over the contents of a CSV row. More...
 

Public Types

using reverse_iterator = std::reverse_iterator< iterator >
 A reverse iterator over the contents of a CSVRow.
 

Public Member Functions

 CSVRow (internals::RawCSVDataPtr _data)
 Construct a CSVRow from a RawCSVDataPtr.
 
 CSVRow (internals::RawCSVDataPtr _data, size_t _data_start, size_t _field_bounds)
 
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.
 
Value Retrieval
CSVField operator[] (size_t n) const
 Return a CSVField object corrsponding to the nth value in the row. More...
 
CSVField operator[] (const std::string &) const
 Retrieve a value by its associated column name. More...
 
std::string to_json (const std::vector< std::string > &subset={}) const
 Convert a CSV row to a JSON object, i.e. More...
 
std::string to_json_array (const std::vector< std::string > &subset={}) const
 Convert a CSV row to a JSON array, i.e. More...
 
std::vector< std::string > get_col_names () const
 Retrieve this row's associated column names.
 
 operator std::vector< std::string > () const
 Convert this CSVRow into a vector of strings. More...
 
Iterators

Each iterator points to a CSVField object.

iterator begin () const
 Return an iterator pointing to the first field.
 
iterator end () const noexcept
 Return an iterator pointing to just after the end of the CSVRow. More...
 
reverse_iterator rbegin () const noexcept
 
reverse_iterator rend () const
 

Detailed Description

Data structure for representing CSV rows.

Definition at line 296 of file csv_row.hpp.

Member Function Documentation

◆ end()

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

Return an iterator pointing to just after the end of the CSVRow.

Warning
Attempting to dereference the end iterator results in dereferencing a null pointer.

Definition at line 180 of file csv_row.cpp.

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

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

Convert this CSVRow into a vector of strings.

Note: This is a less efficient method of accessing data than using the [] operator.

◆ operator[]() [1/2]

CSVField csv::CSVRow::operator[] ( const std::string &  col_name) const

Retrieve a value by its associated column name.

If the column specified can't be round, a runtime error is thrown.

Complexity:\n
Constant. This calls the other CSVRow::operator[]() after converting column names into indices using a hash table.
Parameters
[in]col_nameThe column to look for

Definition at line 47 of file csv_row.cpp.

◆ operator[]() [2/2]

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

Return a CSVField object corrsponding to the nth value in the row.

Note
This method performs bounds checking, and will throw an std::runtime_error if n is invalid.
Complexity:\n
Constant, by calling csv::CSVRow::get_csv::string_view()

Definition at line 34 of file csv_row.cpp.

◆ to_json()

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

Convert a CSV row to a JSON object, i.e.

{"col1":"value1","col2":"value2"}

Note
All strings are properly escaped. Numeric values are not quoted.
Parameters
[in]subsetA subset of columns to contain in the JSON. Leave empty for original columns.

Definition at line 198 of file csv_row_json.cpp.

◆ to_json_array()

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

Convert a CSV row to a JSON array, i.e.

["value1","value2",...]

Note
All strings are properly escaped. Numeric values are not quoted.
Parameters
[in]subsetA subset of columns to contain in the JSON. Leave empty for all columns.

Definition at line 236 of file csv_row_json.cpp.


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