21 #ifndef NS3_CSV_READER_H_
22 #define NS3_CSV_READER_H_
247 CsvReader (
const std::string& filepath,
char delimiter =
',');
257 CsvReader (std::istream& stream,
char delimiter =
',');
308 bool GetValue (std::size_t columnIndex, T& value)
const;
334 bool GetValueAs (std::string input,
double& value)
const;
336 bool GetValueAs (std::string input,
float& value)
const;
338 bool GetValueAs (std::string input,
signed char& value)
const;
340 bool GetValueAs (std::string input,
short& value)
const;
342 bool GetValueAs (std::string input,
int& value)
const;
344 bool GetValueAs (std::string input,
long& value)
const;
346 bool GetValueAs (std::string input,
long long& value)
const;
348 bool GetValueAs (std::string input, std::string& value)
const;
350 bool GetValueAs (std::string input,
unsigned char& value)
const;
352 bool GetValueAs (std::string input,
unsigned short& value)
const;
354 bool GetValueAs (std::string input,
unsigned int& value)
const;
356 bool GetValueAs (std::string input,
unsigned long& value)
const;
358 bool GetValueAs (std::string input,
unsigned long long& value)
const;
375 void ParseLine (
const std::string& line);
385 std::tuple<std::string, std::string::const_iterator>
386 ParseColumn (std::string::const_iterator begin, std::string::const_iterator end);
422 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.