29 #include <type_traits> 33 #include <boost/filesystem.hpp> 34 #include <boost/filesystem/path.hpp> 35 namespace filesys = boost::filesystem;
38 namespace filesys = std::filesystem;
46 class CSV :
protected std::vector<CSVRow>
50 explicit CSV(
const filesys::path& path, std::initializer_list<std::string> optLabels = {});
53 explicit CSV(std::istream& inputStream);
56 explicit CSV(
size_t columnCount);
59 explicit CSV(
const std::vector<std::string>& labels);
62 template <
typename It>
63 explicit CSV(It labelsBegin, It labelsEnd)
72 using std::vector<CSVRow>::begin;
73 using std::vector<CSVRow>::end;
74 using std::vector<CSVRow>::size;
80 template <
typename... T>
81 void AddRow(
const T&... values);
84 void AddRows(
const std::vector<std::vector<std::string>>& rows);
87 void AddRow(
const std::vector<std::string>& row);
93 template <
typename It>
97 this->push_back(csvRow);
108 void Write(
const filesys::path& path)
const;
110 const std::vector<std::string>&
GetLabels()
const;
113 friend std::ofstream&
operator<<(std::ofstream& ofs,
const CSV& csv);
122 void WriteRows(std::ofstream& file)
const;
128 template <
typename... T>
void WriteLabels(std::ofstream &file) const
Write header with labels.
std::string ToString(const T &value)
Builds a string representation of a value of type T.
const std::vector< std::string > & GetLabels() const
bool operator==(const CSV &other) const
Comparison operator.
void Write(const filesys::path &path) const
Write CSV to file.
void ReadFromStream(std::istream &inputStream)
Read data from input stream.
size_t GetIndexForLabel(const std::string &label) const
Convert label to index for more user friendly and robust implementation.
std::vector< std::string > m_labels
size_t GetColumnCount() const
Number of columns in the CSV.
void AddRows(const std::vector< std::vector< std::string >> &rows)
Add multiple rows of strings at the same time.
When it 's not an iterator.
friend std::ofstream & operator<<(std::ofstream &ofs, const CSV &csv)
CSV()=default
Default constructor, used for swig.
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).
Interface/Implementation of is_iterator.
CSV(It labelsBegin, It labelsEnd)
Initialize with header labels only.
void WriteRows(std::ofstream &file) const
Write the body of rows.
Miscellaneous string utilities.
A collection of CSVRow elements.
Header file of base class for config that needs to be read from a file.
void AddRow(const T &...values)
Add row of values.
Namespace for the simulator and related classes.