BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
CSVRow Class Reference

Public Member Functions

void addCell (std::string str)
 
std::vector< std::string > dataVector ()
 
char getSeparator ()
 
std::string const & operator[] (unsigned index) const
 
void readNextRow (std::istream &str)
 
void setSeparator (char sep)
 
unsigned long size () const
 

Private Attributes

std::vector< std::string > m_data
 
char separator = '-'
 

Detailed Description

Definition at line 25 of file CsvReader.h.

Member Function Documentation

◆ addCell()

void CSVRow::addCell ( std::string  str)

Definition at line 60 of file CsvReader.cpp.

61 {
62  m_data.push_back(str);
63 }
std::vector< std::string > m_data
Definition: CsvReader.h:36

References m_data.

Referenced by CSVFile::get_headers(), and readNextRow().

◆ dataVector()

std::vector<std::string> CSVRow::dataVector ( )
inline

Definition at line 33 of file CsvReader.h.

33 { return m_data; }

References m_data.

◆ getSeparator()

char CSVRow::getSeparator ( )

Definition at line 55 of file CsvReader.cpp.

56 {
57  return this->separator;
58 }
char separator
Definition: CsvReader.h:37

References separator.

◆ operator[]()

std::string const & CSVRow::operator[] ( unsigned  index) const

Definition at line 19 of file CsvReader.cpp.

20 {
21  return m_data[index];
22 }

References m_data.

◆ readNextRow()

void CSVRow::readNextRow ( std::istream &  str)

Definition at line 29 of file CsvReader.cpp.

30 {
31  std::string line;
32  std::getline(str, line);
33  std::replace(std::begin(line), std::end(line), '\t', ' ');
34  std::stringstream lineStream(line);
35  std::string cell;
36 
37  m_data.clear();
38 
39  while (std::getline(lineStream, cell, separator)) {
40  addCell(cell);
41  }
42  // This checks for a trailing comma with no data after it.
43  if (!lineStream && cell.empty()) {
44  // If there was a trailing comma then add an empty element.
45  addCell("");
46  }
47 }
void addCell(std::string str)
Definition: CsvReader.cpp:60

References addCell(), m_data, and separator.

Referenced by operator>>().

Here is the call graph for this function:

◆ setSeparator()

void CSVRow::setSeparator ( char  sep)

Definition at line 49 of file CsvReader.cpp.

50 {
51  this->separator = sep;
52  return;
53 }

References separator.

Referenced by CSVIterator::operator++().

◆ size()

unsigned long CSVRow::size ( ) const

Definition at line 24 of file CsvReader.cpp.

25 {
26  return static_cast<unsigned long>(m_data.size());
27 }

References m_data.

Referenced by CSVFile::get_headers().

Member Data Documentation

◆ m_data

std::vector<std::string> CSVRow::m_data
private

Definition at line 36 of file CsvReader.h.

Referenced by addCell(), dataVector(), operator[](), readNextRow(), and size().

◆ separator

char CSVRow::separator = '-'
private

Definition at line 37 of file CsvReader.h.

Referenced by getSeparator(), readNextRow(), and setSeparator().


The documentation for this class was generated from the following files: