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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*****************************************************************************
** FILE IDENTIFICATION
**
** Name: array2d.h
** Purpose: 2-dimension array classes
** Programmer: Kevin Rosenberg
** Date Started: June 2000
**
** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
** $Id: array2d.h 7061 2003-09-07 06:34:45Z kevin $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
** published by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
#ifndef ARRAY2D_H
#define ARRAY2D_H
#include "ctsupport.h"
template<class T>
class Array2d {
public:
Array2d (unsigned int x, unsigned int y)
: m_nx(x), m_ny(y), array_data(0)
{
allocArray();
}
Array2d ()
: m_nx(0), m_ny(0), array_data(0)
{}
~Array2d ()
{
deleteArray();
}
void initSetSize (unsigned int x, unsigned int y)
{
m_nx = x;
m_ny = y;
deleteArray();
allocArray();
}
T** getArray () const
{ return array_data; }
T* getColumn (unsigned int x) const
{ return (array_data ? array_data[x] : NULL); }
T getPoint (unsigned int x, unsigned int y) const
{ return (array_data ? array_data[x][y] : NULL); }
unsigned int sizeofPixel () const
{ return sizeof(T); }
unsigned int sizeofColumn () const
{ return (sizeof(T) * m_ny); }
unsigned int sizeofArray () const
{ return (sizeof(T) * m_nx * m_ny); }
private:
unsigned int m_nx;
unsigned int m_ny;
T** array_data;
void allocArray ()
{
if (array_data)
deleteArray();
array_data = new T*[m_nx];
for (unsigned int i = 0; i < m_nx; i++)
array_data[i] = new T[m_ny];
}
void deleteArray ()
{
if (array_data) {
for (unsigned int i = 0; i < m_nx; i++)
delete array_data [i];
delete array_data;
array_data = NULL;
}
}
Array2d& operator= (const Array2d& rhs); //assignment operator
Array2d (const Array2d& rhs); // copy constructor
};
#endif
|