home *** CD-ROM | disk | FTP | other *** search
- #if !defined(_ISet_)
- #define _ISet_
-
- /*--------------------------------------------------------------*/
- /* CLASS NAMES: ISet */
- /* */
- /* DESCRIPTION : This file defines a class used to implement */
- /* a set mechanism. */
- /* */
- /* 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. */
- /* */
- /* Hungarian form: "set" */
- /* */
- /* 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. */
- /* 02/17/92 CAJ Re-work to Stroustrup */
- /* 09/29/92 RDL c/IGSet/IGSet1 - BB Conflict */
- /*--------------------------------------------------------------*/
- /* Copyright (c) IBM Corporation 1991 */
- /*--------------------------------------------------------------*/
-
- #include <ilinklst.hpp>
-
- class ISet;
-
-
- /*--------------------------------------------------------------*/
- /* Define the Set Class */
- /*--------------------------------------------------------------*/
- class ISet : public ILinkList
- {
- public:
- /*-----------------------------------------------------------*/
- /* Define the Cursor Class */
- /* Note: The set cursor only "sees" objects which have not*/
- /* been filtered out of the set. */
- /*-----------------------------------------------------------*/
- class Cursor : public ILinkListCursor
- {
- public:
-
- /************************************************************/
- /* Normal Set Cursor. Use to move forward and */
- /* backward through the set. */
- /************************************************************/
- Cursor(ISet& iset);
-
-
- /*********************************************************/
- /* Return items in the set (or set view) & move cursor. */
- /*********************************************************/
- void* first();
- void* last();
- void* next();
- void* prior();
-
- virtual Boolean setToFirst() { if (first()!=0)
- return true;
- return false;}
- virtual Boolean setToNext() { if (next()!=0 )
- return true;
- return false;}
- virtual Boolean isValid() const { if (current()!=0)
- return true;
- return false; }
- virtual void invalidate() { reset(); }
-
- private:
- PFNCOMPARE pfnClCompare;
- PFNFILTER pfnClFilter;
- void* pClMask;
- ISet* set() { return (ISet*)plnklCl; }
- };
- friend class Cursor;
- protected:
- /************************************************************/
- /* CONSTRUCTORS */
- /************************************************************/
- ISet(Boolean fDestruct=false,unsigned long ulBase=0)
- : ILinkList(fDestruct,ulBase) {}
- // ISet(void* pObj,Boolean fDestruct=false, unsigned long ulBase=0)
- // : ILinkList(pObj, fDestruct, ulBase) {}
-
- // Copy Constructor
- ISet(const ISet& iset)
- : ILinkList((const ILinkList&)iset) {}
-
- /************************************************************/
- /* Filter/sort set */
- /************************************************************/
- void filter(PFNFILTER pfnFilter);
- Boolean includes(void* pobj);
-
- /************************************************************/
- /* Add to Set */
- /************************************************************/
- Boolean add(void* pobj);
- Boolean addFirst(void* pobj);
- Boolean addLast(void* pobj);
- Boolean addAfter(void* pobj, unsigned long lIndex);
-
- /************************************************************/
- /* Set Assignment */
- /************************************************************/
- ISet& operator=(const ISet& iset);
-
- /************************************************************/
- /* "Destructive" Set Union and Intersection */
- /* - result is left in receiver set */
- /************************************************************/
- void unionWith(const ISet& iset);
- ISet& operator|=(const ISet& iset);
-
- ISet& intersectionWith(const ISet& iset);
- ISet& operator&=(const ISet& iset);
-
- /************************************************************/
- /* "Non-Destructive" Set Union and Intersection */
- /* - receiver set unchanged, result put in new set */
- /************************************************************/
- ISet& unionOf(const ISet& iset);
- ISet& operator|(const ISet& iset);
-
- ISet& intersectOf(const ISet& iset);
- ISet& operator&(const ISet& iset);
-
- protected:
- virtual void deleteObj(void* pobj){ delete pobj; };
- virtual Boolean isEqual(void* pobj1, void* pobj2){return true;};
- INode* search(void *pObj, Boolean fIsForward,
- INode* pnodeStart,PFNCOMPARE pfnCompare);
-
- };
-
-
- /*********************************************************/
- /* Generated set class macro definition */
- /* - name2 macro is defined in ILINKLST.HPP */
- /*********************************************************/
- #define IGSet1(type) name2(IGSet1,type)
-
- #define IGSet1declare(type) \
- class IGSet1(type) : public ISet {\
- public: \
- class Cursor : public ISet::Cursor {\
- public:\
- Cursor(IGSet1(type)& iset) \
- : ISet::Cursor(iset) {}\
- Boolean setToFirst() { return ISet::Cursor::setToFirst(); }\
- Boolean setToNext() { return ISet::Cursor::setToNext(); }\
- Boolean isValid() const { return ISet::Cursor::isValid(); }\
- void invalidate() { ISet::Cursor::invalidate(); }\
- }; \
- IGSet1(type)() : ISet(false,0) { } \
- void removeAt(const Cursor& cursor) { ILinkList::remove(cursor.current()); }\
- type* elementAt(const Cursor& cursor) { return (type*)cursor.current(); }\
- type* elementAtPosition(unsigned long pos) { return (type*)atIndex(pos-1); }\
- unsigned long numberOfElements() { return count(); }\
- Boolean add(type* pobj) { return ISet::addLast(pobj); }\
- void unionWith(const IGSet1(type) & iset) \
- { ISet::unionWith(iset); }\
- IGSet1(type) & operator=(const IGSet1(type) & iset) \
- { return ( IGSet1(type) &)ISet::operator=(iset); }\
- protected:\
- void deleteObj(void* pobj){ delete (type*)pobj; }\
- INode* search(type* pobj,Boolean fForward,INode* pnStart,PFNCOMPARE pfnC) \
- { return ISet::search(pobj,fForward,pnStart,pfnC); }\
- private: \
- Boolean includes(void* pobj) { return ISet::includes(pobj); }\
- Boolean isEqual(void* pobj1, void* pobj2) \
- { return ((type*)pobj1 == (type*)pobj2); }\
- };
-
- #endif