libSplash
Dimensions.hpp
1 
23 #ifndef DIMENSIONS_HPP
24 #define DIMENSIONS_HPP
25 
26 #include <sstream>
27 #include <hdf5.h>
28 
29 #define DSP_DIM_MAX 3
30 
31 namespace splash
32 {
33 
38  class Dimensions
39  {
40  private:
41  hsize_t s[DSP_DIM_MAX];
42  public:
43 
48  Dimensions(void)
49  {
50  set(1, 1, 1);
51  }
52 
59  Dimensions(hsize_t x, hsize_t y, hsize_t z)
60  {
61  set(x, y, z);
62  }
63 
70  hsize_t & operator[](const hsize_t t)
71  {
72  return s[t];
73  }
74 
81  const hsize_t & operator[](const hsize_t t) const
82  {
83  return s[t];
84  }
85 
92  Dimensions operator+(Dimensions const& other) const
93  {
94  return Dimensions(s[0] + other[0], s[1] + other[1], s[2] + other[2]);
95  }
96 
103  Dimensions operator-(Dimensions const& other) const
104  {
105  return Dimensions(s[0] - other[0], s[1] - other[1], s[2] - other[2]);
106  }
107 
114  Dimensions operator*(Dimensions const& other) const
115  {
116  return Dimensions(s[0] * other[0], s[1] * other[1], s[2] * other[2]);
117  }
118 
125  Dimensions operator/(Dimensions const& other) const
126  {
127  return Dimensions(s[0] / other[0], s[1] / other[1], s[2] / other[2]);
128  }
129 
137  {
138  *this = *this + rhs;
139  return *this;
140  }
141 
149  {
150  *this = *this - rhs;
151  return *this;
152  }
153 
160  bool operator==(Dimensions const& other) const
161  {
162  return s[0] == other[0] && s[1] == other[1] && s[2] == other[2];
163  }
164 
171  bool operator!=(Dimensions const& other) const
172  {
173  return !(*this == other);
174  }
175 
181  std::string toString() const
182  {
183  std::stringstream stream;
184  stream << "(" << s[0] << "," << s[1] << "," << s[2] << ")";
185  return stream.str();
186  }
187 
192  inline hsize_t *getPointer()
193  {
194  return s;
195  }
196 
201  inline const hsize_t *getPointer() const
202  {
203  return s;
204  }
205 
210  inline static size_t getSize()
211  {
212  return DSP_DIM_MAX * sizeof (hsize_t);
213  }
214 
219  inline size_t getScalarSize() const
220  {
221  return s[0] * s[1] * s[2];
222  }
223 
230  inline void set(hsize_t x, hsize_t y, hsize_t z)
231  {
232  s[0] = x;
233  s[1] = y;
234  s[2] = z;
235  }
236 
241  inline void set(const Dimensions d)
242  {
243  s[0] = d[0];
244  s[1] = d[1];
245  s[2] = d[2];
246  }
247 
252  inline uint32_t getDims(void) const
253  {
254  uint32_t dims = DSP_DIM_MAX;
255  if (s[2] == 1)
256  {
257  dims = 2;
258  if (s[1] == 1)
259  dims = 1;
260  }
261 
262  return dims;
263  }
264 
269  void swapDims(uint32_t dims)
270  {
271  hsize_t tmp1 = s[0];
272  hsize_t tmp2[DSP_DIM_MAX] = {s[2], s[1], s[0]};
273 
274  switch (dims)
275  {
276  case 2:
277  s[0] = s[1];
278  s[1] = tmp1;
279  break;
280  case 3:
281  for (uint32_t i = 0; i < 3; i++)
282  s[i] = tmp2[i];
283  break;
284  default:
285  return;
286  }
287  }
288 
289  };
290 
291 }
292 
293 #endif /* DIMENSIONS_HPP */
hsize_t * getPointer()
Definition: Dimensions.hpp:192
Dimensions operator*(Dimensions const &other) const
Definition: Dimensions.hpp:114
bool operator==(Dimensions const &other) const
Definition: Dimensions.hpp:160
Dimensions operator+(Dimensions const &other) const
Definition: Dimensions.hpp:92
Dimensions operator+=(Dimensions const &rhs)
Definition: Dimensions.hpp:136
std::string toString() const
Definition: Dimensions.hpp:181
uint32_t getDims(void) const
Definition: Dimensions.hpp:252
Dimensions operator/(Dimensions const &other) const
Definition: Dimensions.hpp:125
size_t getScalarSize() const
Definition: Dimensions.hpp:219
void swapDims(uint32_t dims)
Definition: Dimensions.hpp:269
const hsize_t * getPointer() const
Definition: Dimensions.hpp:201
Dimensions operator-=(Dimensions const &rhs)
Definition: Dimensions.hpp:148
static size_t getSize()
Definition: Dimensions.hpp:210
const hsize_t & operator[](const hsize_t t) const
Definition: Dimensions.hpp:81
Dimensions(hsize_t x, hsize_t y, hsize_t z)
Definition: Dimensions.hpp:59
hsize_t & operator[](const hsize_t t)
Definition: Dimensions.hpp:70
bool operator!=(Dimensions const &other) const
Definition: Dimensions.hpp:171
Dimensions operator-(Dimensions const &other) const
Definition: Dimensions.hpp:103