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_barray_h_
00027 #define _MATRIX_barray_h_
00028
00029 #include "matrix_global.h"
00030 #include "specialType.h"
00031 #include "list.h"
00032
00033
00034
00035
00038 namespace PLib {
00039 template <class T> class BasicArray ;
00040
00041 template <class T> int operator!=(const BasicArray<T>&,const BasicArray<T>&);
00042 template <class T> int operator==(const BasicArray<T>&,const BasicArray<T>&);
00043 template <class T> istream& operator>>(istream& is, BasicArray<T>& arry);
00044 template <class T> ostream& operator<<(ostream& os, const BasicArray<T>& arry);
00045
00046 #include "galloc.h"
00047
00048
00058 template<class T> class BasicArray
00059 {
00060 public:
00061 int n() const
00062 { return sze; }
00063 BasicArray();
00064 BasicArray(const int ni);
00065 BasicArray(const BasicArray<T>& f2);
00066 BasicArray(T* ap, const int size) ;
00067 BasicArray(BasicList<T>& list) ;
00068 virtual ~BasicArray();
00069
00070 BasicArray<T>& operator=(const BasicArray<T>& f2);
00071
00072 int size() const
00073 { return sze; }
00074 void resize(const int nsize)
00075 { resizeBasicArray(*this,nsize) ; }
00076 void resize(const BasicArray<T>& A)
00077 { resize(A.n()); }
00078
00079 void trim(const int nsize);
00080 void clear();
00081 void untrim()
00082 { sze = rsize; }
00083
00084 T& push_back(const T i, int end_buffer=10, double end_mult=-1);
00085
00086
00087 virtual void reset(const T val = 0.0);
00088 T operator=(const T val)
00089 { reset(val); return val; }
00090
00091
00092 T& operator[](const int i)
00093 { return elem(i); }
00094 T operator[](const int i) const
00095 { return elem(i); }
00096
00097 #ifdef DEBUG_PLIB
00098 T& elem(const int i) ;
00099 T elem(const int i) const ;
00100 #else
00101 T& elem(const int i)
00102 { return x[i]; }
00103 T elem(const int i) const
00104 { return x[i]; }
00105 #endif
00106 T* memory() const
00107 { return x ; }
00108
00109 void width(const int w)
00110 { wdth = w; }
00111
00112 #ifdef HAVE_ISO_FRIEND_DECL
00113 friend int operator!= <>(const BasicArray<T>&,const BasicArray<T>&);
00114 friend int operator== <>(const BasicArray<T>&,const BasicArray<T>&);
00115 friend istream& operator>> <>(istream& is, BasicArray<T>& arry);
00116 friend ostream& operator<< <>(ostream& os, const BasicArray<T>& arry);
00117 #else
00118 friend int operator!= (const BasicArray<T>&,const BasicArray<T>&);
00119 friend int operator== (const BasicArray<T>&,const BasicArray<T>&);
00120 friend istream& operator>> (istream& is, BasicArray<T>& arry);
00121 friend ostream& operator<< (ostream& os, const BasicArray<T>& arry);
00122 #endif
00123
00124 ostream& print(ostream& os) const ;
00125
00126 FRIEND_ARRAY_ALLOCATOR
00127
00128
00129 typedef T* iterator ;
00130 typedef const T* const_iterator ;
00131
00132 iterator begin() { return (0<sze) ? x : 0 ; }
00133 const_iterator begin() const { return (0<sze) ? x : 0 ; }
00134
00135 iterator end() { return (0<sze) ? x+sze : 0; }
00136 const_iterator end() const { return (0<sze) ? x+sze : 0; }
00137
00138 protected:
00139 int rsize;
00140 int wdth;
00141 int destruct ;
00142 int sze;
00143 T *x;
00144 };
00145
00146 }
00147
00148 typedef PLib::BasicArray<int> BasicArray_INT ;
00149 typedef PLib::BasicArray<char> BasicArray_BYTE ;
00150 typedef PLib::BasicArray<double> BasicArray_DOUBLE ;
00151 typedef PLib::BasicArray<float> BasicArray_FLOAT ;
00152 typedef PLib::BasicArray<Complex> BasicArray_COMPLEX ;
00153 typedef PLib::BasicArray<unsigned char> BasicArray_UBYTE ;
00154 typedef PLib::BasicArray<PLib::HPoint3Df> BasicArray_HPoint3D ;
00155 typedef PLib::BasicArray<PLib::Point3Df> BasicArray_Point3D ;
00156 typedef PLib::BasicArray<PLib::HPoint3Dd> BasicArray_HPoint3Dd ;
00157 typedef PLib::BasicArray<PLib::Point3Dd> BasicArray_Point3Dd ;
00158 typedef PLib::BasicArray<PLib::HPoint2Df> BasicArray_HPoint2D ;
00159 typedef PLib::BasicArray<PLib::Point2Df> BasicArray_Point2D ;
00160 typedef PLib::BasicArray<PLib::HPoint2Dd> BasicArray_HPoint2Dd ;
00161 typedef PLib::BasicArray<PLib::Point2Dd> BasicArray_Point2Dd ;
00162 typedef PLib::BasicArray<void*> BasicArray_VoidPtr ;
00163 typedef PLib::BasicArray<PLib::Coordinate> BasicArray_Coordinate ;
00164
00165 #ifdef INCLUDE_TEMPLATE_SOURCE
00166 #include "barray.cpp"
00167 #include "barray_hpoint.cpp"
00168 #endif
00169
00170
00171
00172 #endif