#ifndef ARRAY2D_H__ #define ARRAY2D_H__ #include "define.h" template class Array2d { public: Array2d(int x, int y); ~Array2d(); Array2d(const Array2d& array); void Set(int x, int y, T type); T Get(int x, int y) const; void Reset(T type); private: int m_x, m_y; T* m_array; int To1dIndex(int x, int y) const; }; template Array2d::Array2d(int x, int y) : m_x(x), m_y(y) { m_array = new T[m_x * m_y]; } template Array2d::~Array2d() { delete[] m_array; } template Array2d::Array2d(const Array2d& array) : m_x(array.m_x), m_y(array.m_y) { m_array = new BlockType[m_x * m_y]; for (int i = 0; i < m_x * m_y; ++i) m_array[i] = array.m_array[i]; } template void Array2d::Set(int x, int y, T type) { m_array[To1dIndex(x, y)] = type; } template T Array2d::Get(int x, int y) const { return m_array[To1dIndex(x, y)]; } template void Array2d::Reset(T type) { for (int i = 0; i < m_x * m_y; ++i) m_array[i] = type; } template int Array2d::To1dIndex(int x, int y) const { return x + (y * m_x); } #endif // ARRAY2D_H__