Stride Reference Manual  - generated for commit 9643b11
stride::util::CSV Class Reference

A collection of CSVRow elements. More...

#include <CSV.h>

Inheritance diagram for stride::util::CSV:
Inheritance graph
Collaboration diagram for stride::util::CSV:
Collaboration graph

Public Member Functions

 CSV (const filesys::path &path, std::initializer_list< std::string > optLabels={})
 Initialize from file. If optLabels not specifed, the file is required. More...
 
 CSV (std::istream &inputStream)
 Initialize from inputstream. More...
 
 CSV (size_t columnCount)
 Initialize with columnCount only; labels default to sequence numbers. More...
 
 CSV (const std::vector< std::string > &labels)
 Initialize with header only. More...
 
template<typename It >
 CSV (It labelsBegin, It labelsEnd)
 Initialize with header labels only. More...
 
 CSV ()=default
 Default constructor, used for swig. More...
 
bool operator== (const CSV &other) const
 Comparison operator. More...
 
template<typename... T>
void AddRow (const T &...values)
 Add row of values. More...
 
void AddRows (const std::vector< std::vector< std::string >> &rows)
 Add multiple rows of strings at the same time. More...
 
void AddRow (const std::vector< std::string > &row)
 Add a row of strings. More...
 
template<typename It >
void AddRow (typename std::enable_if< is_iterator< It >::value, It >::type first, It last)
 Add row of values (ToString handles the case when the iterator points to strings). More...
 
size_t GetColumnCount () const
 Number of columns in the CSV. More...
 
size_t GetIndexForLabel (const std::string &label) const
 Convert label to index for more user friendly and robust implementation. More...
 
void Write (const filesys::path &path) const
 Write CSV to file. More...
 
const std::vector< std::string > & GetLabels () const
 

Private Member Functions

void ReadFromStream (std::istream &inputStream)
 Read data from input stream. More...
 
void WriteLabels (std::ofstream &file) const
 Write header with labels. More...
 
void WriteRows (std::ofstream &file) const
 Write the body of rows. More...
 

Private Attributes

std::vector< std::string > m_labels
 
size_t m_column_count = 0
 

Friends

std::ofstream & operator<< (std::ofstream &ofs, const CSV &csv)
 

Detailed Description

A collection of CSVRow elements.

Iterate with begin and end like STL containers.

Definition at line 46 of file CSV.h.

Constructor & Destructor Documentation

stride::util::CSV::CSV ( const filesys::path &  path,
std::initializer_list< std::string >  optLabels = {} 
)
explicit

Initialize from file. If optLabels not specifed, the file is required.

Definition at line 48 of file CSV.cpp.

References m_column_count, m_labels, and ReadFromStream().

Here is the call graph for this function:

stride::util::CSV::CSV ( std::istream &  inputStream)
explicit

Initialize from inputstream.

Definition at line 70 of file CSV.cpp.

References ReadFromStream().

Here is the call graph for this function:

stride::util::CSV::CSV ( size_t  columnCount)
explicit

Initialize with columnCount only; labels default to sequence numbers.

Definition at line 74 of file CSV.cpp.

References m_labels, and stride::util::ToString().

Here is the call graph for this function:

stride::util::CSV::CSV ( const std::vector< std::string > &  labels)
explicit

Initialize with header only.

Definition at line 72 of file CSV.cpp.

template<typename It >
stride::util::CSV::CSV ( It  labelsBegin,
It  labelsEnd 
)
inlineexplicit

Initialize with header labels only.

Definition at line 63 of file CSV.h.

References AddRow(), AddRows(), CSV(), and operator==().

Here is the call graph for this function:

stride::util::CSV::CSV ( )
default

Default constructor, used for swig.

Referenced by CSV().

Here is the caller graph for this function:

Member Function Documentation

bool stride::util::CSV::operator== ( const CSV other) const

Comparison operator.

Definition at line 88 of file CSV.cpp.

References m_labels.

Referenced by CSV().

Here is the caller graph for this function:

template<typename... T>
void stride::util::CSV::AddRow ( const T &...  values)
inline

Add row of values.

Definition at line 129 of file CSV.h.

References stride::util::ToString().

Referenced by AddRows(), CSV(), and ReadFromStream().

Here is the call graph for this function:

Here is the caller graph for this function:

void stride::util::CSV::AddRows ( const std::vector< std::vector< std::string >> &  rows)

Add multiple rows of strings at the same time.

Definition at line 81 of file CSV.cpp.

References AddRow().

Referenced by CSV().

Here is the call graph for this function:

Here is the caller graph for this function:

void stride::util::CSV::AddRow ( const std::vector< std::string > &  row)

Add a row of strings.

Definition at line 157 of file CSV.cpp.

template<typename It >
void stride::util::CSV::AddRow ( typename std::enable_if< is_iterator< It >::value, It >::type  first,
It  last 
)
inline

Add row of values (ToString handles the case when the iterator points to strings).

Template Parameters
ItIterator type pointing to the values.
Parameters
firstStart of the range to be included
lastPast-the-end of the range.

Definition at line 94 of file CSV.h.

References stride::util::ToString().

Here is the call graph for this function:

size_t stride::util::CSV::GetColumnCount ( ) const
inline

Number of columns in the CSV.

Definition at line 101 of file CSV.h.

References GetIndexForLabel(), GetLabels(), m_column_count, operator<<, ReadFromStream(), Write(), WriteLabels(), and WriteRows().

Referenced by stride::util::CSVRow::CSVRow(), stride::util::CSVRow::GetValue< std::string >(), and geopop::CommutesCSVReader::FillGeoGrid().

Here is the call graph for this function:

Here is the caller graph for this function:

size_t stride::util::CSV::GetIndexForLabel ( const std::string &  label) const

Convert label to index for more user friendly and robust implementation.

This level of indirection does introduce a perfomance tradeoff.

Definition at line 93 of file CSV.cpp.

References m_labels.

Referenced by stride::util::CSVRow::GetValue< std::string >(), and GetColumnCount().

Here is the caller graph for this function:

void stride::util::CSV::Write ( const filesys::path &  path) const

Write CSV to file.

Definition at line 102 of file CSV.cpp.

Referenced by GetColumnCount().

Here is the caller graph for this function:

const std::vector< std::string > & stride::util::CSV::GetLabels ( ) const

Definition at line 163 of file CSV.cpp.

References m_labels.

Referenced by geopop::CommutesCSVReader::FillGeoGrid(), and GetColumnCount().

Here is the caller graph for this function:

void stride::util::CSV::ReadFromStream ( std::istream &  inputStream)
private

Read data from input stream.

Definition at line 133 of file CSV.cpp.

References AddRow(), m_column_count, m_labels, stride::util::Split(), and stride::util::Trim().

Referenced by CSV(), and GetColumnCount().

Here is the call graph for this function:

Here is the caller graph for this function:

void stride::util::CSV::WriteLabels ( std::ofstream &  file) const
private

Write header with labels.

Definition at line 113 of file CSV.cpp.

References m_labels.

Referenced by GetColumnCount(), and stride::util::operator<<().

Here is the caller graph for this function:

void stride::util::CSV::WriteRows ( std::ofstream &  file) const
private

Write the body of rows.

Definition at line 126 of file CSV.cpp.

Referenced by GetColumnCount(), and stride::util::operator<<().

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ofstream& operator<< ( std::ofstream &  ofs,
const CSV csv 
)
friend

Definition at line 134 of file CSV.h.

Referenced by GetColumnCount().

Member Data Documentation

std::vector<std::string> stride::util::CSV::m_labels
private

Definition at line 124 of file CSV.h.

Referenced by CSV(), GetIndexForLabel(), GetLabels(), operator==(), ReadFromStream(), and WriteLabels().

size_t stride::util::CSV::m_column_count = 0
private

Definition at line 125 of file CSV.h.

Referenced by CSV(), GetColumnCount(), and ReadFromStream().


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