Line | |
---|
1 | #ifndef GFXTOOLS_ARRAY3_INCLUDED // -*- C++ -*-
|
---|
2 | #define GFXTOOLS_ARRAY3_INCLUDED
|
---|
3 |
|
---|
4 | template<class T>
|
---|
5 | class array3
|
---|
6 | {
|
---|
7 | protected:
|
---|
8 | T *data;
|
---|
9 | int w, h, d;
|
---|
10 |
|
---|
11 | public:
|
---|
12 | array3() { data=NULL; w=h=d=0; }
|
---|
13 | array3(int w, int h, int d) { init(w,h,d); }
|
---|
14 | ~array3() { free(); }
|
---|
15 |
|
---|
16 | inline void init(int w, int h, int d);
|
---|
17 | inline void free();
|
---|
18 |
|
---|
19 |
|
---|
20 | inline T& ref(int i, int j, int k);
|
---|
21 | inline T& operator()(int i,int j, int k) { return ref(i,j, k); }
|
---|
22 |
|
---|
23 | inline int width() const { return w; }
|
---|
24 | inline int height() const { return h; }
|
---|
25 | inline int depth() const { return d; }
|
---|
26 | };
|
---|
27 |
|
---|
28 | template<class T>
|
---|
29 | inline void array3<T>::init(int width, int height, int depth)
|
---|
30 | {
|
---|
31 | w = width;
|
---|
32 | h = height;
|
---|
33 | d = depth;
|
---|
34 | data = new T[w*h*d];
|
---|
35 | }
|
---|
36 |
|
---|
37 | template<class T>
|
---|
38 | inline void array3<T>::free()
|
---|
39 | {
|
---|
40 | if( data )
|
---|
41 | {
|
---|
42 | delete[] data;
|
---|
43 | data = NULL;
|
---|
44 | w = h = d = 0;
|
---|
45 | }
|
---|
46 |
|
---|
47 | }
|
---|
48 |
|
---|
49 | template<class T>
|
---|
50 | inline T& array3<T>::ref(int i, int j, int k)
|
---|
51 | {
|
---|
52 | #ifdef SAFETY
|
---|
53 | assert( data );
|
---|
54 | assert( i>=0 && i<w );
|
---|
55 | assert( j>=0 && j<h );
|
---|
56 | assert( k>=0 && k<d );
|
---|
57 | #endif
|
---|
58 | return data[k*w*h + j*w + i];
|
---|
59 | }
|
---|
60 |
|
---|
61 | // GFXTOOLS_ARRAY3_INCLUDED
|
---|
62 | #endif
|
---|
Note: See
TracBrowser
for help on using the repository browser.