Simpact Cyan
Population based event driven simulation using mNRM
csvfile.h
Go to the documentation of this file.
1 #ifndef CSVFILE_H
2 
3 #define CSVFILE_H
4 
9 #include "errut/errorbase.h"
10 #include <vector>
11 
32 class CSVFile : public errut::ErrorBase
33 {
34 public:
35  CSVFile();
36  ~CSVFile();
37 
39  bool load(const std::string &fileName);
40 
42  int getNumberOfColumns();
43 
45  int getNumberOfRows();
46 
48  bool hasValue(int row, int column);
49 
51  double getValue(int row, int column);
52 
54  const std::string getColumnName(int col) const;
55 private:
56  bool checkNumber(const std::string &s, double &value);
57 
58  std::vector<std::string> m_headers;
59  std::vector<std::vector<double> > m_values;
60  std::vector<std::vector<bool> > m_map;
61 };
62 
63 #endif // CSVFILE_H
Base class which allows an error message to be set.
Definition: errorbase.h:49
int getNumberOfColumns()
Returns the number of columns in the loaded file.
Definition: csvfile.cpp:116
int getNumberOfRows()
Returns the number of rows in the loaded file.
Definition: csvfile.cpp:123
This is a helper class for reading CSV files, which are assumed to hold numbers.
Definition: csvfile.h:32
bool load(const std::string &fileName)
Try to load the specified file, setting the error string if failed.
Definition: csvfile.cpp:14
double getValue(int row, int column)
Returns the stored value for the specified position.
Definition: csvfile.cpp:137
bool hasValue(int row, int column)
Returns true if a numerical value exists for the specified position.
Definition: csvfile.cpp:128
const std::string getColumnName(int col) const
Returns the name of the specified column (from the header).
Definition: csvfile.cpp:142