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
00027
00028 template <class Type>
00029 class Array2 {
00030 protected:
00031 int _length0;
00032 int _length1;
00033 int _managed;
00034 Type * _array;
00035 public:
00036 Array2():_length0(0),_length1(0),_array(0) {}
00037 Array2(const Array2<Type> &a): _length0(0),_length1(0),_array(0) {
00038 operator=(a);
00039 }
00040 Array2(Type* data,int size0,int size1):
00041 _length0(size0),_length1(size1),_managed(0),_array(data) {}
00042 Array2(int size0,int size1): _length0(0),_length1(0),_array(0) {
00043 set_lengths(size0,size1);
00044 }
00045 ~Array2() { clear(); }
00046 int length0() const { return _length0; };
00047 int length1() const { return _length1; };
00048 void clear() { set_lengths(0,0); }
00049 void set_lengths(int size0,int size1) {
00050 if (_managed && _array) delete[] _array;
00051 _managed = 1;
00052 if (size0*size1) _array = new Type [ size0*size1 ];
00053 else _array = 0;
00054 _length0 = size0;
00055 _length1 = size1;
00056 }
00057 Array2<Type>& operator = (const Array2<Type> & s) {
00058 if (_managed && _array) delete[] _array;
00059 _managed = 1;
00060 _length0 = s._length0;
00061 _length1 = s._length1;
00062 if (_length0*_length1) _array = new Type [ _length0*_length1 ];
00063 else _array = 0;
00064 for (int i=0; i<_length0*_length1; i++) {
00065 _array[i] = s._array[i];
00066 }
00067 return (*this);
00068 }
00069 Type& operator() (int i,int j) {
00070 if (i<0 || i>=_length0 || j<0 || j>=_length1) {
00071 ExEnv::err() << "Array2::operator()(" << i << "," << j << "): "
00072 << "out of range (" << _length0 << "," << _length1
00073 << ",)" << std::endl;
00074 abort();
00075 };
00076 return _array[i*_length1+j];
00077 }
00078 const Type& operator() (int i,int j) const {
00079 if (i<0 || i>=_length0 || j<0 || j>=_length1) {
00080 ExEnv::err() << "Array2::operator()(" << i << "," << j << "): "
00081 << "out of range (" << _length0 << "," << _length1
00082 << ",)" << std::endl;
00083 abort();
00084 };
00085 return _array[i*_length1+j];
00086 }
00087 };
00088
00089
00090
00091
00092
00093
00094