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