Simpact Cyan
Population based event driven simulation using mNRM
gridvaluescsv.h
1 #ifndef GRIDVALUESCSV_H
2 
3 #define GRIDVALUESCSV_H
4 
5 #include "gridvalues.h"
6 #include "booltype.h"
7 #include "csvfile.h"
8 #include <assert.h>
9 #include <vector>
10 
11 class GridValuesCSV : public GridValues
12 {
13 public:
14  GridValuesCSV();
15  ~GridValuesCSV();
16 
17  bool_t init(const std::string &fileName, bool noNegativeValues = true, bool flipY = false);
18 
19  int getWidth() const { return m_width; }
20  int getHeight() const { return m_height; }
21 
22  double getValue(int x, int y) const;
23  void setValue(int x, int y, double v);
24 
25  bool isYFlipped() const { return m_flipped; }
26 
27  std::string getFileName() const { return m_fileName; }
28 private:
29  std::vector<double> m_values;
30  int m_width, m_height;
31  bool m_flipped;
32  std::string m_fileName;
33 };
34 
35 inline double GridValuesCSV::getValue(int x, int y) const
36 {
37  assert(x >= 0 && x < m_width && y >= 0 && y < m_height);
38  return m_values[x+y*m_width]; // values were flipped when loading
39 }
40 
41 inline void GridValuesCSV::setValue(int x, int y, double v)
42 {
43  assert(x >= 0 && x < m_width && y >= 0 && y < m_height);
44  m_values[x+y*m_width] = v;
45 }
46 
47 #endif // GRIDVALUESCSV_H
Type to return true/false with error description.
Definition: booltype.h:25