r109: reorganized header files
[ctsim.git] / include / array2d.h
index 01c272982d031c373bc809410fe3fe8a7b5e22bb..5eb23b3804b3e66424399ff806f99672da05cc71 100644 (file)
@@ -1,44 +1,80 @@
+/*****************************************************************************
+** 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-2000 Kevin Rosenberg
+**
+**  $Id: array2d.h,v 1.5 2000/06/19 19:04:05 kevin Exp $
+**  $Log: array2d.h,v $
+**  Revision 1.5  2000/06/19 19:04:05  kevin
+**  reorganized header files
+**
+**  Revision 1.4  2000/06/09 11:03:08  kevin
+**  Made ImageFile inherit from Array2dFile
+**
+**  Revision 1.3  2000/06/09 01:35:33  kevin
+**  Convert MPI structure to C++ class
+**
+**
+**  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 <kstddef.h>
+#include "ctsupport.h"
+
 
 template<class T> 
 class Array2d {
- private:
-    unsigned int nx;
-    unsigned int ny;
-
  public:
-
-    T** array_data;
-
     Array2d (unsigned int x, unsigned int y)
+       : nx(x), ny(y), array_data(0)
        {
-           nx = x;
-           ny = y;
-           array_data = new T*[nx];
-           
-           for (unsigned int i = 0; i < nx; i++)
-               array_data[i] = new T[ny];
+           allocArray();
        }
 
+    Array2d (void)
+       : array_data(0), nx(0), ny(0)
+       {}
 
     ~Array2d ()
        {
-           for (int i = 0; i < nx; i++)
-               delete array_data[i];
-           delete array_data;
+           deleteArray();
        }
     
+    void initSetSize (unsigned int x, unsigned int y)
+       {
+           nx = x;
+           ny = y;
+           deleteArray();
+           allocArray();
+       }
+
     T** getArray (void) const
        { return array_data; }
 
     T* getColumn (unsigned int x) const
-       { return array_data[x]; }
+       { return (array_data ? array_data[x] : NULL); }
 
     T getPoint (unsigned int x, unsigned int y) const
-       { return (array_data[x][y]); }
+       { return (array_data ? array_data[x][y] : NULL); }
 
     unsigned int sizeofPixel (void) const 
        {  return sizeof(T); }
@@ -48,6 +84,33 @@ class Array2d {
 
     unsigned int sizeofArray (void) const
        { return (sizeof(T) * nx * ny); }
+
+
+ private:
+    unsigned int nx;
+    unsigned int ny;
+    T** array_data;
+
+    void allocArray (void)
+       {
+           array_data = new T*[nx];
+           
+           for (unsigned int i = 0; i < nx; i++)
+               array_data[i] = new T[ny];
+       }
+
+    void deleteArray (void)
+       {
+           if (array_data) {
+               for (int i = 0; i < nx; i++)
+                   delete array_data[i];
+               delete array_data;
+           }
+       }
+
+
+    Array2d& operator= (const Array2d& rhs);
+    Array2d (const Array2d& rhs);  // copy constructor
 };