Main Page   Class Hierarchy   Compound List   File List   Compound Members  

barray2d.h

00001 /*=============================================================================
00002         File: barray2d.h
00003      Purpose:       
00004     Revision: $Id: barray2d.h,v 1.3 2002/05/17 14:52:12 philosophil Exp $
00005   Created by: Philippe Lavoie          (3 Oct, 1996)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1998 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024 =============================================================================*/
00025 
00026 #ifndef _Matrix_barray2d_h_
00027 #define _Matrix_barray2d_h_
00028 
00029 
00030 #include <fstream>
00031 #include <iomanip>
00032 #include "specialType.h"
00033 
00034 // Predefining every friend functions 
00035 // This is required by latest ISO C++ draft
00036 
00039 namespace PLib {
00040   template <class T> class Basic2DArray ;
00041 
00042   template <class T> istream& operator>>(istream& is, Basic2DArray<T>& ary);
00043   template <class T> ostream& operator<<(ostream& os, const Basic2DArray<T>& ary);
00044 
00045 
00046 #include "galloc2d.h"
00047 
00057 template<class T> class Basic2DArray
00058 {
00059 public:
00060   int rows() const 
00061     { return rz;} 
00062   int cols() const 
00063     { return cz;} 
00064   Basic2DArray() ;
00065   Basic2DArray(const int r, const int c) ;
00066   Basic2DArray(const Basic2DArray<T>& f2);
00067   Basic2DArray(T* p, const int r, const int c) ;
00068   
00069   virtual ~Basic2DArray();
00070   
00071   Basic2DArray<T>& operator=(const Basic2DArray<T>& f2);
00072   
00073   void resize(const int nr, const int nc); 
00074   void resize(const Basic2DArray<T>& A) { resize(A.rows(),A.cols()) ; }
00075   void resizeKeep(const int nr, const int nc) { resizeKeepBasic2DArray(*this,nr,nc) ; }
00076 
00077   void reset(const T val = 0.0);
00078   T operator=(const T val) 
00079     { reset(val); return val; } 
00080 
00081   T* operator[](const int i) 
00082     { return vm[i]; } 
00083   T* operator[](const int i) const 
00084     { return vm[i];} 
00085   
00086   T& operator()(const int i,const int j)  
00087     { return elem(i,j); } 
00088   T  operator()(const int i,const int j) const 
00089     { return elem(i,j); } 
00090 
00091   void io_elem_width(int w) 
00092     { width = w ; }
00093   void io_by_rows()   
00094     { by_columns = 0; }  
00095   void io_by_columns()  
00096     { by_columns = 1; } 
00097 
00098   ostream& print(ostream& os) const ; 
00099 
00100 #ifdef HAVE_ISO_FRIEND_DECL
00101   friend istream& operator>> <>(istream& is, Basic2DArray<T>& ary);
00102   friend ostream& operator<< <>(ostream& os, const Basic2DArray<T>& ary);
00103 #else
00104   friend istream& operator>> (istream& is, Basic2DArray<T>& ary);
00105   friend ostream& operator<< (ostream& os, const Basic2DArray<T>& ary);
00106 #endif
00107 
00108 #ifdef DEBUG_PLIB
00109   T& elem(const int i,const int j);  // returns an error message if the index is out of range
00110   T  elem(const int i,const int j) const;   // returns an error message if the index is out of range
00111 #else
00112 #ifdef COLUMN_ORDER
00113   T& elem(const int i,const int j) 
00114     { return vm[j][i] ; }  // no error message are generated if the index are out of range
00115   T  elem(const int i,const int j) const
00116     { return vm[j][i] ; }  // no error message are generated if the index are out of range
00117 #else
00118   T& elem(const int i,const int j) 
00119     { return vm[i][j] ; }  // no error message are generated if the index are out of range
00120   T  elem(const int i,const int j) const
00121     { return vm[i][j] ; }  // no error message are generated if the index are out of range
00122 #endif
00123 #endif
00124   
00125   FRIEND_2DARRAY_ALLOCATOR
00126 
00127 
00128   
00129 protected:
00130   int by_columns; 
00131   int width; 
00132   int rz; 
00133   int cz; 
00134   T *m;  
00135   T **vm ;  
00136   int created ; 
00137 
00138   void init(const int r = 1, const int c = 1) 
00139     { initBasic2DArray(*this,r,c); }
00140 
00141 };
00142 
00143 } // end namespace
00144 
00145 typedef PLib::Basic2DArray<int> Array2D_INT ;            
00146 typedef PLib::Basic2DArray<char> Array2D_BYTE ;          
00147 typedef PLib::Basic2DArray<double> Array2D_DOUBLE ;      
00148 typedef PLib::Basic2DArray<Complex> Array2D_COMPLEX ;    
00149 typedef PLib::Basic2DArray<unsigned char> Array2D_UBYTE ;
00150 typedef PLib::Basic2DArray<PLib::Point3Df> Array2D_Point3Df ;
00151 typedef PLib::Basic2DArray<PLib::HPoint3Df> Array2D_HPoint3Df ;
00152 typedef PLib::Basic2DArray<PLib::Point3Dd> Array2D_Point3Dd ;
00153 typedef PLib::Basic2DArray<PLib::HPoint3Dd> Array2D_HPoint3Dd ;
00154 typedef PLib::Basic2DArray<PLib::Coordinate> Array2D_Coordinate ;
00155 
00156 #ifdef INCLUDE_TEMPLATE_SOURCE
00157 #include "barray2d.cpp"
00158 #include "barray2d_hpoint.cpp"
00159 #endif
00160 
00161 
00162 
00163 #endif
00164 

Generated on Tue Jun 24 13:26:54 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002