Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ArrayList.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the ToolBox.
00003  * Copyright Thomas Jacob.
00004  *
00005  * READ README.TXT BEFORE USE!!
00006  */
00007 
00008 
00009 #ifndef __TOOLBOX_ARRAYLIST_H
00010 #define __TOOLBOX_ARRAYLIST_H
00011 
00012 
00016 #define _TB_AL_DEFAULTINITSIZE          16
00017 
00021 #define _TB_AL_DEFAULTMINIMUMFILLRATIO  30
00022 
00026 #define _TB_AL_DEFAULTDESIREDFILLRATIO  60
00027 
00028 
00029 namespace toolbox
00030 {
00042    #if defined(_DEBUG) && (defined(_AFX) || defined(_AFXDLL))
00043       template <class ELEMENTTYPE> class ArrayList : public CObject
00044    #else
00045       template <class ELEMENTTYPE> class ArrayList
00046    #endif
00047    {
00048       private:
00049 
00054          long Count;
00055 
00064          int DesiredFillRatio;
00065 
00069          ELEMENTTYPE ** Elements;
00070 
00075          long InitSize;
00076 
00077          #ifdef _TOOLBOX_TEST
00078 
00081             static int InstanceCount;
00082          #endif
00083 
00089          int MinimumFillRatio;
00090 
00096          long Size;
00097 
00103          void CheckSize(int newSize);
00104 
00111          void Init(long initSize, int minimumFillRatio, int desiredFillRatio);
00112 
00118          void Resize(long newSize);
00119 
00120       public:
00121 
00125          ArrayList();
00126 
00131          ArrayList(long initSize);
00132 
00139          ArrayList(long initSize, int minimumFillRatio, int desiredFillRatio);
00140 
00145          virtual ~ArrayList();
00146 
00151          void Append(ELEMENTTYPE * Element);
00152 
00159          void AppendAll(const ArrayList<ELEMENTTYPE> * Elements);
00160 
00172          virtual int Compare(const ELEMENTTYPE * Element1, const ELEMENTTYPE * Element2) const;
00173 
00181          bool Contains(const ELEMENTTYPE * Element) const;
00182 
00193          bool Contains(const ELEMENTTYPE * Element,
00194             int (* compare)(const ELEMENTTYPE * Element1, const ELEMENTTYPE * Element2)) const;
00195 
00202          bool Delete(long nr);
00203 
00213          bool Delete(long from, long count);
00214 
00223          bool Delete(ELEMENTTYPE * Element);
00224 
00229          void DeleteAll();
00230 
00237          inline bool DeleteFirst();
00238 
00245          bool DeleteLast();
00246 
00255          int Find(const ELEMENTTYPE * Element) const;
00256 
00268          int Find(const ELEMENTTYPE * Element,
00269             int (* compare)(const ELEMENTTYPE * Element1, const ELEMENTTYPE * Element2)) const;
00270 
00276          ELEMENTTYPE * Get(long nr) const;
00277 
00283          inline long GetCount() const;
00284 
00290          inline int GetDesiredFillRatio() const;
00291 
00296          inline int GetFillRatio() const;
00297 
00303          ELEMENTTYPE * GetFirst() const;
00304 
00310          ELEMENTTYPE * GetLast() const;
00311 
00317          inline int GetMinimumFillRatio() const;
00318 
00325          void Insert(ELEMENTTYPE * Element, long nr);
00326 
00335          void InsertAll(const ArrayList<ELEMENTTYPE> * Elements, long nr);
00336 
00340          inline bool IsEmpty() const;
00341 
00346          inline void Prepend(ELEMENTTYPE * Element);
00347 
00354          inline void PrependAll(const ArrayList<ELEMENTTYPE> * Elements);
00355 
00364          ELEMENTTYPE * Replace(ELEMENTTYPE * NewElement, long nr);
00365 
00366          #ifdef _TOOLBOX_TEST
00367 
00373             static void RunTestSuite(int * performedTests, int * failedTests);
00374          #endif
00375 
00379          void Shuffle();
00380 
00387          inline void Sort();
00388 
00399          void Sort(int (* compare)(const ELEMENTTYPE * Element1, const ELEMENTTYPE * Element2));
00400 
00408          ELEMENTTYPE * Unlink(long nr);
00409 
00418          ELEMENTTYPE * Unlink(ELEMENTTYPE * Element);
00419 
00429          bool Unlink(long from, long count);
00430 
00437          void UnlinkAll();
00438 
00445          inline ELEMENTTYPE * UnlinkFirst();
00446 
00453          ELEMENTTYPE * UnlinkLast();
00454    };
00455 }
00456 
00457 
00458 #endif

Generated on Tue Oct 3 00:23:38 2006 for ToolBox by doxygen 1.3.6