-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray2d.h
More file actions
107 lines (88 loc) · 2.13 KB
/
array2d.h
File metadata and controls
107 lines (88 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef TAK__ARRAY2D_H__
#define TAK__ARRAY2D_H__
#include "define.h"
#include <cassert>
template <class T>
class Array2d
{
public:
Array2d(unsigned int x, unsigned int y);
~Array2d();
Array2d(const Array2d<T>& array);
void Set(unsigned int x, unsigned int y, T type);
const T& Get(unsigned int x, unsigned int y) const;
T& Get(unsigned int x, unsigned int y);
unsigned int SizeX() const;
unsigned int SizeY() const;
void Reset(T type);
private:
unsigned int m_x, m_y;
T* m_array;
T& GetElement(unsigned int x, unsigned int y);
const T& GetElement(unsigned int x, unsigned int y) const;
};
template <class T>
Array2d<T>::Array2d(unsigned int x, unsigned int y) : m_x(x), m_y(y)
{
m_array = new T[m_x * m_y];
}
template <class T>
Array2d<T>::~Array2d()
{
delete [] m_array;
}
template <class T>
Array2d<T>::Array2d(const Array2d& array)
{
m_x = array.m_x;
m_y = array.m_y;
m_array = new T[m_x * m_y];
for(unsigned int i = 0; i < m_x * m_y; ++i)
m_array[i] = array.m_array[i];
}
template <class T>
void Array2d<T>::Set(unsigned int x, unsigned int y, T type)
{
GetElement(x, y) = type;
}
template <class T>
const T& Array2d<T>::Get(unsigned int x, unsigned int y) const
{
return GetElement(x, y);
}
template <class T>
T& Array2d<T>::Get(unsigned int x, unsigned int y)
{
return GetElement(x, y);
}
template <class T>
unsigned int Array2d<T>::SizeX() const
{
return m_x;
}
template <class T>
unsigned int Array2d<T>::SizeY() const
{
return m_y;
}
template <class T>
void Array2d<T>::Reset(T type)
{
for(unsigned int i = 0; i < m_x * m_y; ++i)
m_array[i] = type;
}
template <class T>
T& Array2d<T>::GetElement(unsigned int x, unsigned int y)
{
assert(x < m_x);
assert(y < m_y);
return m_array[x + (y * m_x)];
}
template <class T>
const T& Array2d<T>::GetElement(unsigned int x, unsigned int y) const
{
assert(x < m_x);
assert(y < m_y);
return m_array[x + (y * m_x)];
}
#endif // ARRAY2D_H__