9#ifndef NS3_CSV_READER_H_
10#define NS3_CSV_READER_H_
232 CsvReader(
const std::string& filepath,
char delimiter =
',');
242 CsvReader(std::istream& stream,
char delimiter =
',');
293 bool GetValue(std::size_t columnIndex, T& value)
const;
319 bool GetValueAs(std::string input,
double& value)
const;
321 bool GetValueAs(std::string input,
float& value)
const;
323 bool GetValueAs(std::string input,
signed char& value)
const;
325 bool GetValueAs(std::string input,
short& value)
const;
327 bool GetValueAs(std::string input,
int& value)
const;
329 bool GetValueAs(std::string input,
long& value)
const;
331 bool GetValueAs(std::string input,
long long& value)
const;
333 bool GetValueAs(std::string input, std::string& value)
const;
335 bool GetValueAs(std::string input,
unsigned char& value)
const;
337 bool GetValueAs(std::string input,
unsigned short& value)
const;
339 bool GetValueAs(std::string input,
unsigned int& value)
const;
341 bool GetValueAs(std::string input,
unsigned long& value)
const;
343 bool GetValueAs(std::string input,
unsigned long long& value)
const;
370 std::tuple<std::string, std::string::const_iterator>
ParseColumn(
371 std::string::const_iterator begin,
372 std::string::const_iterator end);
407 std::string cell =
m_columns[columnIndex];
Provides functions for parsing and extracting data from Comma Separated Value (CSV) formatted text fi...
virtual ~CsvReader()
Destructor.
bool GetValue(std::size_t columnIndex, T &value) const
Attempt to convert from the string data in the specified column to the specified data type.
std::size_t RowNumber() const
The number of lines that have been read.
char Delimiter() const
Returns the delimiter character specified during object construction.
std::istream * m_stream
Pointer to the input stream containing the data.
bool IsDelimiter(char c) const
Returns true if the supplied character matches the delimiter.
CsvReader(const std::string &filepath, char delimiter=',')
Constructor.
void ParseLine(const std::string &line)
Scans the string and splits it into individual columns based on the delimiter.
std::size_t ColumnCount() const
Returns the number of columns in the csv data.
std::size_t m_rowsRead
Number of lines processed.
std::ifstream m_fileStream
File stream containing the data.
bool m_blankRow
Line contains no data (blank line or comment only).
bool FetchNextRow()
Reads one line from the input until a new line is encountered.
std::vector< std::string > Columns
Container of CSV data.
bool IsBlankRow() const
Check if the current row is blank.
Columns m_columns
Fields extracted from the current line.
bool GetValueAs(std::string input, double &value) const
Attempt to convert from the string data stored at the specified column index into the specified type.
char m_delimiter
Character used to separate fields.
std::tuple< std::string, std::string::const_iterator > ParseColumn(std::string::const_iterator begin, std::string::const_iterator end)
Extracts the data for one column in a csv row.
Every class exported by the ns3 library is enclosed in the ns3 namespace.