r90: Convert MPI structure to C++ class
[ctsim.git] / include / array2d.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **      Name:         array2d.h
5 **      Purpose:      2-dimension array classes
6 **      Programmer:   Kevin Rosenberg
7 **      Date Started: June 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: array2d.h,v 1.3 2000/06/09 01:35:33 kevin Exp $
13 **  $Log: array2d.h,v $
14 **  Revision 1.3  2000/06/09 01:35:33  kevin
15 **  Convert MPI structure to C++ class
16 **
17 **
18 **  This program is free software; you can redistribute it and/or modify
19 **  it under the terms of the GNU General Public License (version 2) as
20 **  published by the Free Software Foundation.
21 **
22 **  This program is distributed in the hope that it will be useful,
23 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
24 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 **  GNU General Public License for more details.
26 **
27 **  You should have received a copy of the GNU General Public License
28 **  along with this program; if not, write to the Free Software
29 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30 ******************************************************************************/
31
32 #ifndef ARRAY2D_H
33 #define ARRAY2D_H
34
35 #include <kstddef.h>
36
37 template<class T> 
38 class Array2d {
39  private:
40     unsigned int nx;
41     unsigned int ny;
42
43  public:
44
45     T** array_data;
46
47     Array2d (unsigned int x, unsigned int y)
48         {
49             nx = x;
50             ny = y;
51             array_data = new T*[nx];
52             
53             for (unsigned int i = 0; i < nx; i++)
54                 array_data[i] = new T[ny];
55         }
56
57
58     ~Array2d ()
59         {
60             for (int i = 0; i < nx; i++)
61                 delete array_data[i];
62             delete array_data;
63         }
64     
65     T** getArray (void) const
66         { return array_data; }
67
68     T* getColumn (unsigned int x) const
69         { return array_data[x]; }
70
71     T getPoint (unsigned int x, unsigned int y) const
72         { return (array_data[x][y]); }
73
74     unsigned int sizeofPixel (void) const 
75         {  return sizeof(T); }
76
77     unsigned int sizeofColumn (void) const
78         { return (sizeof(T) * ny); }
79
80     unsigned int sizeofArray (void) const
81         { return (sizeof(T) * nx * ny); }
82 };
83
84
85 #endif