home *** CD-ROM | disk | FTP | other *** search
- #if !defined(_ILinkList_)
- #define _ILinkList_
-
- /*--------------------------------------------------------------*/
- /* CLASS NAMES: INode */
- /* ILinkList --> IGLinkList */
- /* ILinkListCursor --> IGLinkListCursor */
- /* */
- /* DESCRIPTION : This file defines a set of classes used to */
- /* implement a doubly linked list, which is the */
- /* basis of the Collection classes in ICLUI. */
- /* */
- /* The collection classes in ICLUI are a */
- /* merger between the SList/SLink generic */
- /* collection classes described by Bjarne */
- /* Stroustrup in Vol 1 of "The C++ Programming */
- /* Language" and the original typeless, */
- /* shallow-copy classes designed by Mike Chan */
- /* and Kevin Leong in Dallas. */
- /* */
- /* The basic link list mechanism provides the */
- /* capability to deal with void* elements where */
- /* the caller is responsible for allocation and */
- /* destruction. There is also a macro to create */
- /* a "generated" collection class which allows */
- /* ICLUI collections to deal with objects of */
- /* any class in a type safe manner. */
- /* */
- /* The generated class is defined as: */
- /* IGLinkList(MyObj) myObjList; */
- /* */
- /* The Linklist provides cursor movement both */
- /* within the ILinkList class and as a separate */
- /* ILinkListCursor class which enables the use */
- /* of multiple cursors on the same link list. */
- /* There is a macro for creating "generated" */
- /* cursors too. */
- /* */
- /* Hungarian form : "lknl" - linklist */
- /* : "lknlc" - cursor */
- /* */
- /* CHANGE ACTIVITY: */
- /* --------------- */
- /* DATE: INITIAL: DESCRIPTION: */
- /* */
- /* 03/01/91 KKL Design & architecture */
- /* 03/28/91 WC Init declaration */
- /* 05/01/91 KKL Extend to support IGENOBJ */
- /* 06/08/91 KKL Tidy-up and re-organize methods. */
- /* 12/23/91- RDL Re-work to Stroustrup */
- /* 03/31/92 CAJ */
- /*--------------------------------------------------------------*/
- /* Copyright (c) IBM Corporation 1991 */
- /*--------------------------------------------------------------*/
- #include <ibasetyp.hpp> /* IBM C++ OS/2 2.0 */
-
- #if (OS2LEVEL > 130)
- extern "C" // RDL 32 bit
- {
- #include <stddef.h>
- }
- #else
- #include <stddef.h>
- #endif
- /*--------------------------------------------------------------*/
- /* Generic class construction Macros */
- /*--------------------------------------------------------------*/
- #if !defined(name2)
- // The name macro is used to patch together two words
- #define name2(n1,n2) n1 ## n2
- #endif
-
- #if !defined(declare)
- // This macro is used to construct a class name
- #define declare(a,type) a##declare(type)
- #endif
-
- #if !defined(implement)
- // This macro is used to construct a class name
- #define implement(a,type) a##implement(type)
- #endif
-
- class INode;
- class ILinkList;
- class ILinkListCursor;
-
- /*--------------------------------------------------------------*/
- /* Definition of Comparison and Sorting function types */
- /*--------------------------------------------------------------*/
- #if (OS2LEVEL > 130)
- /* IBM C++ OS/2 2.0 */
- extern "C" {
- typedef long (_System FNCOMPARE)(void* pobj1, // RDL 32 bit
- void* pobj2,
- ILinkList* pcoll);
- typedef FNCOMPARE *PFNCOMPARE; // RDL 32 bit
-
- typedef Boolean (_System FNFILTER)(void* pobj, // RDL 32 bit
- ILinkList* pcoll);
- typedef FNFILTER *PFNFILTER; // RDL 32 bit
- }
-
- #else
- /* Zortech OS/2 1.3 */
- extern "C" {
- typedef int (PASCAL FAR *PFNCOMPARE)(void* pobj1,
- void* pobj2,
- ILinkList* pcoll);
-
- typedef Boolean (PASCAL FAR *PFNFILTER)(void* pobj,
- ILinkList* pcoll);
- }
-
- #endif
-
-
- /*--------------------------------------------------------------*/
- /* A Node in the Linked List class definition */
- /* Hungarian form : "node" */
- /*--------------------------------------------------------------*/
- class INode
- {
- friend class ILinkList;
- friend class ILinkListCursor;
-
- public:
- INode() { pClObj = 0; }
- void* object() { return pClObj; }
-
- // Add later- Deal with small objects more efficiently */
- // void* operator new(size_t);
- // void operator delete(void*, size_t);
-
- INode* pnodeClNext;
- INode* pnodeClPrev;
- void* pClObj;
- };
-
-
- /*--------------------------------------------------------------*/
- /* The Double Link List of Nodes class definition */
- /*--------------------------------------------------------------*/
- class ILinkList
- {
- friend class ILinkListCursor;
-
- public:
- static unsigned notInList;
- /*********************************************************/
- /* CONSTRUCTORS/DESTRUCTOR: */
- /* - If the fDestruct flag is true, the ILinkList */
- /* destructor will delete the objects in the list. */
- /* - The ulBase value provides the list indexing base. */
- /*********************************************************/
- ILinkList(Boolean fDestruct=false, unsigned long ulBase=0);
- ILinkList(void* pObj, Boolean fDestruct=false, unsigned long ulBase=0);
- ILinkList(const ILinkList& lnklst);
-
- virtual ~ILinkList();
-
- /*********************************************************/
- /* Add current, first, last, and at an index. */
- /*********************************************************/
- Boolean add(void* pobj);
- Boolean addFirst(void* pobj);
- Boolean addLast(void* pobj);
- Boolean addAfter(void* pobj, unsigned long lIndex );
-
- /*********************************************************/
- /* Remove and return the current item and the first item*/
- /*********************************************************/
- void* remove();
- void* remove(void* pobj);
- void* removeFirst();
-
- /*********************************************************/
- /* Clear the list. */
- /*********************************************************/
- void removeAll();
-
- /*********************************************************/
- /* Move through the list (updates current). */
- /*********************************************************/
- void toFirst();
- void toLast();
- unsigned long toIndex(unsigned long lIndex);
- void toNext();
- void toPrior();
-
- /*********************************************************/
- /* Return some items in the List. */
- /*********************************************************/
- void* current() const;
- void* first();
- void* last();
- void* next();
- void* prior();
- void* atIndex(unsigned long lIndex);
-
- /************************************************************/
- /* Get the index of current node or the index of a node */
- /* pointing to a given object. The index is adjusted for */
- /* the indexing base. Return code of hex all F's means */
- /* the object is not in the list. */
- /************************************************************/
- unsigned long indexOf();
- unsigned long indexOf(void* pobj);
-
- /************************************************************/
- /* Check if linked list is empty. */
- /************************************************************/
- Boolean isEmpty();
-
- /************************************************************/
- /* Data element access functions. */
- /************************************************************/
- unsigned long base(); // retrieve indexing base number
- unsigned long count() const; // get number of objects on list
-
-
- protected:
- /************************************************************/
- /* Get the index of a given INode in the linked list. */
- /* The index is adjusted for the indexing base. Return of */
- /* hex all F's indicates an object was not in the list. */
- /************************************************************/
- unsigned long indexOf(INode* pnode);
-
- /*********************************************************/
- /* Delete object pointed to from INode. Virtual at this*/
- /* level as type of object is needed. This info is */
- /* obtained from IGLinkListTYPE class macro. */
- /*********************************************************/
- virtual void ILinkList::deleteObj(void* pobj){ delete pobj;}
-
- // Make the connection on node.
- INode* link(INode* pnode);
-
- // Unlink the current or specified node.
- INode* unLink();
- INode* unLink(INode* pnode);
-
- // Internal default sort functions
- void quickSort(INode* pnodeFirst, INode* pnodeLast,
- PFNCOMPARE pfnCompare );
- INode* partition(INode* pnodeLeft, INode* pnodeRight,
- void *pobjPivot, PFNCOMPARE pfnCompare);
-
-
- // Data elements
- INode* pnodeClHead; // HEAD node pointer
- INode* pnodeClTail; // TAIL node pointer
- INode* pnodeClCurrent; // CURRENT node pointer
- Boolean fClDestruct; // object destruct flag
- unsigned long ulClCount; // number of objects in list
-
- private:
- unsigned long ulClListBase; // indexing base number
- };
-
- /*--------------------------------------------------------------*/
- /* The Link List Cursor. */
- /*--------------------------------------------------------------*/
- class ILinkListCursor
- {
- public:
- friend class ILinkList;
-
- /*********************************************************/
- /* CONSTRUCTORS/DESTRUCTOR: */
- /*********************************************************/
- ILinkListCursor(ILinkList& lnklst);
-
- /*********************************************************/
- /* Return items in the list and update the cursor. */
- /*********************************************************/
- void* current() const;
- void* first();
- void* last();
- void* next();
- void* prior();
-
- /*********************************************************/
- /* Reset the Cursor. */
- /* Note: Current() is undefined following a reset(). */
- /*********************************************************/
- void reset() { pnodeClCursor = plnklCl->pnodeClHead; }
-
- protected:
- INode* headNode() { return plnklCl->pnodeClHead; }
- INode* tailNode() { return plnklCl->pnodeClTail; }
-
- INode* pnodeClCursor;
- ILinkList* plnklCl;
- };
-
-
- /*********************************************************/
- /* Generated linklist class macro definition */
- /*********************************************************/
- #define IGLinkList(type) name2(IGLinkList,type)
- #define IGLinkListCursor(type) name2(IGLinkListCursor,type)
-
-
- #define IGLinkListdeclare(type)\
- class IGLinkList(type) : public ILinkList {\
- public:\
- IGLinkList(type)(Boolean fDestruct=false,unsigned long ulBaseIn=0) \
- : ILinkList(fDestruct,ulBaseIn) {}\
- IGLinkList(type)(type* pobj,Boolean fDestruct=false,unsigned long ulBaseIn=0) \
- : ILinkList((void *) pobj,fDestruct,ulBaseIn) {}\
- Boolean add(type* pobj) { return ILinkList::add(pobj); }\
- Boolean addFirst(type* pobj) { return ILinkList::addFirst(pobj); }\
- Boolean addLast(type* pobj) { return ILinkList::addLast(pobj); }\
- Boolean addAfter(type* pobj, unsigned long ul) \
- { return ILinkList::addAfter(pobj,ul); }\
- type* remove() { return (type*)ILinkList::remove(); }\
- type* remove(type* pobj) { return (type*)ILinkList::remove((void*)pobj); }\
- type* removeFirst() { return (type*)ILinkList::removeFirst(); }\
- type* current() { return (type*)ILinkList::current(); }\
- type* first() { return (type*)ILinkList::first(); }\
- type* last() { return (type*)ILinkList::last(); }\
- type* next() { return (type*)ILinkList::next(); }\
- type* prior() { return (type*)ILinkList::prior(); }\
- unsigned long indexOf() { return ILinkList::indexOf(); }\
- unsigned long indexOf(type* pobj) { return ILinkList::indexOf((void*)pobj);}\
- protected: \
- void deleteObj(void* pobj){ delete (type*)pobj; }\
- private:\
- IGLinkList(type)(const IGLinkList(type) & lnklst){} \
- IGLinkList(type) &operator=(const IGLinkList(type) &);\
- };
-
- /*********************************************************/
- /* Generated linklist cursor class macro definition */
- /*********************************************************/
- #define IGLinkListCursordeclare(type)\
- class IGLinkListCursor(type) : public ILinkListCursor {\
- public:\
- IGLinkListCursor(type)(IGLinkList(type)& lnklst) \
- : ILinkListCursor(lnklst) {}\
- type* current() { return (type*)ILinkListCursor::current(); }\
- type* first() { return (type*)ILinkListCursor::first(); }\
- type* last() { return (type*)ILinkListCursor::last(); }\
- type* next() { return (type*)ILinkListCursor::next(); }\
- type* prior() { return (type*)ILinkListCursor::prior(); }\
- };
- #endif