Stride Reference Manual
- generated for commit 9643b11
|
A collection of CSVRow elements. More...
#include <CSV.h>
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) |
A collection of CSVRow elements.
Iterate with begin and end like STL containers.
|
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().
|
explicit |
Initialize from inputstream.
Definition at line 70 of file CSV.cpp.
References ReadFromStream().
|
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().
|
explicit |
|
inlineexplicit |
|
default |
Default constructor, used for swig.
Referenced by CSV().
bool stride::util::CSV::operator== | ( | const CSV & | other | ) | const |
|
inline |
Add row of values.
Definition at line 129 of file CSV.h.
References stride::util::ToString().
Referenced by AddRows(), CSV(), and ReadFromStream().
void stride::util::CSV::AddRows | ( | const std::vector< std::vector< std::string >> & | rows | ) |
void stride::util::CSV::AddRow | ( | const std::vector< std::string > & | row | ) |
|
inline |
Add row of values (ToString handles the case when the iterator points to strings).
It | Iterator type pointing to the values. |
first | Start of the range to be included |
last | Past-the-end of the range. |
Definition at line 94 of file CSV.h.
References stride::util::ToString().
|
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().
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().
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().
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().
|
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().
|
private |
Write header with labels.
Definition at line 113 of file CSV.cpp.
References m_labels.
Referenced by GetColumnCount(), and stride::util::operator<<().
|
private |
Write the body of rows.
Definition at line 126 of file CSV.cpp.
Referenced by GetColumnCount(), and stride::util::operator<<().
|
friend |
Definition at line 134 of file CSV.h.
Referenced by GetColumnCount().
|
private |
Definition at line 124 of file CSV.h.
Referenced by CSV(), GetIndexForLabel(), GetLabels(), operator==(), ReadFromStream(), and WriteLabels().
|
private |
Definition at line 125 of file CSV.h.
Referenced by CSV(), GetColumnCount(), and ReadFromStream().