Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

rtcollect.h

Go to the documentation of this file.
00001 /*
00002  * rtcollect.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 // MSVC++ Bug Workaround
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 } // namespace
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 

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer