source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Array2.h @ 774

Revision 774, 1015 bytes checked in by gumbau, 18 years ago (diff)

GTGeometry and GeoTool? initial imports

Line 
1#ifndef GFXTOOLS_ARRAY2_INCLUDED // -*- C++ -*-
2#define GFXTOOLS_ARRAY2_INCLUDED
3
4template<class T>
5class array2 {
6protected:
7    T *data;
8    int w, h;
9public:
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
23template<class T>
24inline void array2<T>::init(int width,int height)
25{
26    w = width;
27    h = height;
28    data = new T[w*h];
29}
30
31template<class T>
32inline void array2<T>::free()
33{
34    if( data )
35    {
36        delete[] data;
37        data = NULL;
38    }
39}
40
41template<class T>
42inline 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.