29 inline bool IsFloat(
const std::string& s)
32 std::stringstream ss(s);
33 return (ss >> a) ?
true :
false;
41 CSVRow::CSVRow(
const CSV* parent,
const std::vector<std::string>& values) : m_parent(parent), m_values()
44 throw std::runtime_error(
"Tried adding row with " +
ToString(values.size()) +
" value(s) to CSV with " +
47 for (
const std::string& value : values) {
54 std::string CSVRow::GetValue<std::string>(
size_t index)
const 57 throw std::runtime_error(
"Index out of range for CSV: " +
ToString(index));
64 std::string CSVRow::GetValue<std::string>(
const std::string& label)
const 74 for (
unsigned int i = 0; i < row.
m_values.size(); ++i) {
75 const std::string& value = row.
m_values.at(i);
76 if (!IsFloat(value)) {
80 if (!IsFloat(value)) {
std::string ToString(const T &value)
Builds a string representation of a value of type T.
bool operator==(const CSVRow &other) const
Compare operator.
size_t GetIndexForLabel(const std::string &label) const
Convert label to index for more user friendly and robust implementation.
std::vector< std::string > m_values
size_t GetColumnCount() const
Number of columns in the CSV.
T GetValue(size_t index) const
Get value at index. When T is specified, StringUtils are used to try to convert the value to type T...
friend std::ostream & operator<<(std::ostream &os, const CSVRow &row)
Print to stream.
CSVRow(const CSV *parent, const std::vector< std::string > &values)
CSVRow initialized with values. Should no be called by user code. CSV has convenience functions...
std::string Trim(const std::string &source, const std::string &t=" ")
Trim characters at both ends of string.
A collection of CSVRow elements.
Header file of base class for config that needs to be read from a file.
Namespace for the simulator and related classes.
Header file of base class for config that needs to be read from a file.