-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathArray3D.h
77 lines (63 loc) · 1.25 KB
/
Array3D.h
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
/**
* \file Array3D.h
* \brief Contains class for large 3D Arrays
*/
#ifndef ARRAY3D_H_
#define ARRAY3D_H_
/**
* \class Array3D
* \brief Template Class for large 3D Arrays
*
* Note: The vector of vector of vector notation for 3D arrays has problems with such large dimensions
*/
template <class T>
class Array3D
{
private:
/** X Dimension */
int _nDimX;
/** Y Dimension */
int _nDimY;
/** Z Dimension */
int _nDimZ;
public:
/** Pointer to the data */
T * * *_;
/** Constructor, allocates the space in each dimension */
Array3D(const int x, const int y, const int z)
{
_nDimX = x;
_nDimY = y;
_nDimZ = z;
_ = new T * *[_nDimX];
for( int i = 0; i < _nDimX; ++i )
{
_[i] = new T *[_nDimY];
for( int j = 0; j < _nDimY; ++j )
{
_[i][j] = new T[_nDimZ];
}
}
}
/** Deconstructor, deletes the data */
~Array3D()
{
delete _; //HACK: This is a huge memory leak here
}; // maybe have to iterate through matrix and delete
/** Get the X dimensions */
int dimX()
{
return _nDimX;
}
/** Get the Y dimensions */
int dimY()
{
return _nDimY;
}
/** Get the Z dimensions */
int dimZ()
{
return _nDimZ;
}
};
#endif