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

LinkedList.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_LINKEDLIST_H
00010 #define __TOOLBOX_LINKEDLIST_H
00011 
00012 
00013 namespace toolbox
00014 {
00033    template <class ITEMTYPE> class ContainingList
00034    {
00035       private:
00036 
00040          long Count;
00041 
00045          ITEMTYPE * First;
00046 
00047          #ifdef _TOOLBOX_TEST
00048 
00051             static int InstanceCount;
00052          #endif
00053 
00057          ITEMTYPE * Last;
00058 
00059       public:
00060 
00064          ContainingList();
00065 
00070          virtual ~ContainingList();
00071 
00076          void Append(ITEMTYPE * Item);
00077 
00090          virtual int Compare(const ITEMTYPE * Item1, const ITEMTYPE * Item2) const;
00091 
00098          bool Delete(long nr);
00099 
00108          bool Delete(ITEMTYPE * Item);
00109 
00119          bool Delete(ITEMTYPE * Item, int (* compare)(const ITEMTYPE * Item1, const ITEMTYPE * Item2));
00120 
00125          void DeleteAll();
00126 
00135          inline void DeleteDirectly(ITEMTYPE * Item);
00136 
00142          bool DeleteFirst();
00143 
00149          bool DeleteLast();
00150 
00156          ITEMTYPE * Get(long nr) const;
00157 
00166          inline ITEMTYPE * Get(const ITEMTYPE * SearchItem) const;
00167 
00176          ITEMTYPE * Get(const ITEMTYPE * SearchItem,
00177             int (* compare)(const ITEMTYPE * Item1, const ITEMTYPE * Item2)) const;
00178 
00183          inline long GetCount() const;
00184 
00189          inline ITEMTYPE * GetFirst() const;
00190 
00195          inline ITEMTYPE * GetLast() const;
00196 
00202          void Insert(ITEMTYPE * Item, long nr);
00203 
00207          inline bool IsEmpty() const;
00208 
00213          inline void Prepend(ITEMTYPE * Item);
00214 
00221          void Reverse();
00222 
00223          #ifdef _TOOLBOX_TEST
00224 
00230             static void RunTestSuite(int * performedTests, int * failedTests);
00231          #endif
00232 
00239          inline void Sort();
00240 
00251          void Sort(int (* compare)(const ITEMTYPE * Item1, const ITEMTYPE * Item2));
00252 
00259          ITEMTYPE * Unlink(long nr);
00260 
00269          ITEMTYPE * Unlink(ITEMTYPE * Item);
00270 
00280          ITEMTYPE * Unlink(ITEMTYPE * Item, int (* compare)(const ITEMTYPE * Item1, const ITEMTYPE * Item2));
00281 
00288          void UnlinkAll();
00289 
00299          ITEMTYPE * UnlinkDirectly(ITEMTYPE * Item);
00300 
00306          inline ITEMTYPE * UnlinkFirst();
00307 
00313          ITEMTYPE * UnlinkLast();
00314    };
00315 
00316 
00329    template <class ITEMTYPE> class ContainingListItem
00330    {
00331       friend class ContainingList<ITEMTYPE>;
00332 
00333       private:
00334 
00335          #ifdef _TOOLBOX_TEST
00336 
00339             static int InstanceCount;
00340          #endif
00341 
00346          ITEMTYPE * NextItem;
00347 
00352          ITEMTYPE * PrevItem;
00353 
00354       public:
00355 
00359          ContainingListItem();
00360 
00364          virtual ~ContainingListItem();
00365 
00370          inline ITEMTYPE * GetNext() const;
00371 
00376          inline ITEMTYPE * GetPrev() const;
00377 
00378          #ifdef _TOOLBOX_TEST
00379 
00385             static void RunTestSuite(int * performedTests, int * failedTests);
00386          #endif
00387    };
00388 
00389 
00408    class PointeredList : public ContainingList<PointeredListItem>
00409    {
00410       private:
00411 
00412          #ifdef _TOOLBOX_TEST
00413 
00416             static int InstanceCount;
00417          #endif
00418 
00419       public:
00420 
00424          PointeredList();
00425 
00432          virtual ~PointeredList();
00433 
00442          static int CaseInsensitiveStringCompare(const PointeredListItem * Item1, const PointeredListItem * Item2);
00443 
00452          static int CaseSensitiveStringCompare(const PointeredListItem * Item1, const PointeredListItem * Item2);
00453 
00454          #ifdef _TOOLBOX_TEST
00455 
00461             static void RunTestSuite(int * performedTests, int * failedTests);
00462          #endif
00463    };
00464 
00465 
00478    class PointeredListItem : public ContainingListItem<PointeredListItem>
00479    {
00480       private:
00481 
00485          void * Data;
00486 
00487          #ifdef _TOOLBOX_TEST
00488 
00491             static int InstanceCount;
00492          #endif
00493 
00494       public:
00495 
00499          PointeredListItem();
00500 
00504          virtual ~PointeredListItem();
00505 
00510          inline void * GetData() const;
00511 
00512          #ifdef _TOOLBOX_TEST
00513 
00519             static void RunTestSuite(int * performedTests, int * failedTests);
00520          #endif
00521 
00526          inline void SetData(void * Data);
00527    };
00528 }
00529 
00530 
00531 #endif

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