2021-10-11 11:37:58 -04:00
|
|
|
#ifndef ARRAY3D_H__
|
|
|
|
#define ARRAY3D_H__
|
|
|
|
|
|
|
|
#include "define.h"
|
|
|
|
|
|
|
|
template <class T>
|
2021-10-19 14:29:06 -04:00
|
|
|
class Array3d {
|
2021-10-11 11:37:58 -04:00
|
|
|
public:
|
|
|
|
Array3d(int x, int y, int z);
|
|
|
|
~Array3d();
|
|
|
|
Array3d(const Array3d& array);
|
|
|
|
|
|
|
|
void Set(int x, int y, int z, T type);
|
|
|
|
T Get(int x, int y, int z) const;
|
|
|
|
|
|
|
|
void Reset(T type);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_x, m_y, m_z;
|
|
|
|
T* m_array;
|
2021-10-19 14:29:06 -04:00
|
|
|
|
|
|
|
int To1dIndex(int x, int y, int z) const;
|
2021-10-11 11:37:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
2021-10-19 12:22:25 -04:00
|
|
|
Array3d<T>::Array3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z) { m_array = new T[m_x * m_y * m_z]; }
|
2021-10-11 11:37:58 -04:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
Array3d<T>::~Array3d() { delete[] m_array; }
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
Array3d<T>::Array3d(const Array3d<T>& array) : m_x(array.m_x), m_y(array.m_y), m_z(array.m_z) {
|
2021-11-01 12:36:53 -04:00
|
|
|
m_array = new T[m_x * m_y * m_z];
|
2021-10-11 11:37:58 -04:00
|
|
|
for (int i = 0; i < m_x * m_y * m_z; ++i)
|
|
|
|
m_array[i] = array.m_array[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void Array3d<T>::Set(int x, int y, int z, T type) {
|
|
|
|
m_array[To1dIndex(x, y, z)] = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2021-10-19 14:29:06 -04:00
|
|
|
T Array3d<T>::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; }
|
2021-10-11 11:37:58 -04:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void Array3d<T>::Reset(T type) {
|
|
|
|
for (int i = 0; i < m_x * m_y * m_z; ++i)
|
|
|
|
m_array[i] = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2021-10-19 14:29:06 -04:00
|
|
|
int Array3d<T>::To1dIndex(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); }
|
2021-10-11 11:37:58 -04:00
|
|
|
|
|
|
|
#endif // ARRAY3D_H__
|