00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021 #ifndef __LRT_COLLECT__
00022 #define __LRT_COLLECT__
00023
00024 #include "rtsystem.h"
00025 #include "rtdefs.h"
00026 #include "rtmath.h"
00027
00028 namespace lrt {
00029
00033 template<class T> class Array {
00034 public:
00036 explicit Array(int length);
00037
00039 Array(const Array<T>&);
00040
00044 Array(const T* ptr, int off, int len);
00045
00047 virtual ~Array();
00048
00050 inline int length() const;
00051
00055 inline const T& operator[](int index) const;
00056
00061 inline T& operator[](int index);
00062
00065 Array<T>& operator= (const Array<T>&);
00066
00072 inline const T* getData() const;
00073
00078 int indexOf(const T& elem, int pos = 0) const;
00079
00081 inline void exchange(int p1, int p2);
00082
00085 inline void sort();
00086
00088 void reverse();
00089
00091 void sort(int (*compareFun)(const T&, const T&), int l = 0, int r = Math::MAX_INT);
00092
00093 protected:
00095 int len;
00097 T* data;
00098
00102 inline int check(int);
00103
00107 inline int checkConst(int) const;
00108
00111 static void copy(const Array<T> *source, int srcPos, Array<T> *dest, int destPos, int length);
00112 };
00113
00121 template<class T> class Vector : public Array<T> {
00122
00123 public:
00125 explicit Vector(int length = 0);
00126
00128 Vector(const Vector<T>&);
00129
00133 inline const T& operator[](int index) const;
00134
00142 inline T& operator[](int index);
00143
00146 Vector<T>& operator= (const Vector<T>&);
00147
00150 int check(int);
00151
00155 Vector<T>& operator +=(const T &);
00156
00160 Vector<T>& operator += (const Array<T> &);
00161
00165 void insert(T elem, int before);
00166
00170 void remove(int pos);
00171
00174 void remove(int start, int length);
00175
00177 void clear();
00178
00179 protected:
00181 int capacity;
00182
00186 inline int up2pow(int val);
00187
00190 static void copy(const Array<T> *source, int srcPos, Vector<T> *dest, int destPos, int length);
00191 };
00192
00193
00194 #ifndef __LRT_TPTR_DEFINED
00195 #define __LRT_TPTR_DEFINED
00196 LRT_DEFINE_PTR(T)
00197 #endif // TPTR_DEFINED
00198
00202 template<class LRT_NPTR(T)> void deleteAt(Vector<LRT_PTR(T)>& vect, int index);
00203
00206 template<class LRT_NPTR(T)> void deleteAll(Vector<LRT_PTR(T)>& vect);
00207
00208
00209 }
00210
00211 #ifndef __MSVC__ // can't cope with the template specializations
00212 #define __LRT_SPECIALIZE_COLLECT__
00213 #include "rtcollect.special.h"
00214 #endif // MSVC
00215
00216 #include "rtcollect.templ.cpp"
00217
00218 #endif
00219