00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00035
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);
00110 T elem(
const int i,
const int j)
const;
00111
#else
00112
#ifdef COLUMN_ORDER
00113
T& elem(
const int i,
const int j)
00114 {
return vm[j][i] ; }
00115 T elem(
const int i,
const int j)
const
00116
{
return vm[j][i] ; }
00117
#else
00118
T& elem(
const int i,
const int j)
00119 {
return vm[i][j] ; }
00120 T elem(
const int i,
const int j)
const
00121
{
return vm[i][j] ; }
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 }
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