home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.5 KB | 175 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PRList.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
- // Note: These classes are private to the implementation. They are not available
- // to part handlers.
- //
- // Note: These are primitive classes for implementing higher-level collections
- // For example, to create a FrameList class, subclass FW_CPrivLink to add a field to
- // store the frame. The FrameList class would use a FW_CPrivLinkedList in its implementation
- // and would manufacture the FW_CPrivLink objects internally.
- //
- // Note: SimpleLinkedList is a list without a "seed" for consistency checking.
- // It cannot be iterated over.
-
- #ifndef PRLIST_H
- #define PRLIST_H
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- //========================================================================================
- // class FW_CPrivLink
- //========================================================================================
-
- class FW_CPrivLink
- {
- //----------------------------------------------------------------------------------------
- // Constructors/Destructor
- //
- public:
- FW_CPrivLink();
- FW_CPrivLink(FW_CPrivLink* next, FW_CPrivLink* previous);
- FW_CPrivLink( const FW_CPrivLink& );
- virtual ~FW_CPrivLink();
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- FW_CPrivLink* GetNext() const
- {return fNext;}
- FW_CPrivLink* GetPrevious() const
- {return fPrevious;}
-
- // The following operations are provided for efficiency, but DO NOT USE THEM
- // if there are any iterators active on a list. These operations don't bump
- // the list's fSeed and the iterators will not be able to detect that they
- // are out of sync!
-
- void Remove();
- void AddBefore(FW_CPrivLink *aLink);
- void AddAfter(FW_CPrivLink *aLink);
-
- //private-by-convention:
-
- void SetNext(FW_CPrivLink* aLink)
- {fNext = aLink;}
- void SetPrevious(FW_CPrivLink* aLink)
- {fPrevious = aLink;}
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- private:
- FW_CPrivLink* fNext;
- FW_CPrivLink* fPrevious;
- };
-
- //========================================================================================
- // class FW_CPrivLinkedList
- //========================================================================================
-
- class FW_CPrivLinkedList
- {
- public:
- friend class FW_CPrivLinkedListIterator;
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructor
- //
- public:
- FW_CPrivLinkedList();
- ~FW_CPrivLinkedList();
-
- //----------------------------------------------------------------------------------------
- // LinkedList API
- //
- public:
- FW_Boolean IsEmpty() const;
- unsigned long Count() const;
- FW_Boolean Includes(const FW_CPrivLink* aLink) const;
-
- void Remove(FW_CPrivLink* aLink);
- void RemoveAll();
- void DeleteAllLinks();
-
- FW_CPrivLink* RemoveFirst();
- FW_CPrivLink* RemoveLast();
-
- void AddBefore(FW_CPrivLink* existing, FW_CPrivLink* link);
- void AddAfter(FW_CPrivLink* existing, FW_CPrivLink* link);
- void AddFirst(FW_CPrivLink* link);
- void AddLast(FW_CPrivLink* link);
- void AddLast(FW_CPrivLinkedList &list);
- void AddLastUnique(FW_CPrivLinkedList &list);
-
- FW_CPrivLink* After(const FW_CPrivLink* link) const;
- FW_CPrivLink* Before(const FW_CPrivLink* link) const;
- FW_CPrivLink* First() const;
- FW_CPrivLink* Last() const;
-
- protected:
- FW_CPrivLink* GetSentinel()
- {return &fSentinel;}
- const FW_CPrivLink* GetSentinel() const
- {return &fSentinel;}
- FW_Boolean IsSentinel( const FW_CPrivLink* link ) const
- {return link==this->GetSentinel();}
- FW_Boolean NotSentinel( const FW_CPrivLink* link ) const
- {return link!=this->GetSentinel();}
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- private:
- FW_CPrivLink fSentinel; // Marks the head & tail
- unsigned long fSeed; // Used to detect out-of-sync iterators
- unsigned long fCount; // Number of elements in the list
- };
-
- //========================================================================================
- // FW_CPrivLinkedListIterator
- //========================================================================================
-
- class FW_CPrivLinkedListIterator
- {
- //----------------------------------------------------------------------------------------
- // Constructors/Destructor
- //
- public:
- FW_CPrivLinkedListIterator(FW_CPrivLinkedList* list);
- ~FW_CPrivLinkedListIterator();
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivLinkedListIterator API
- //
- public:
- FW_CPrivLink* First();
- FW_CPrivLink* Next();
- FW_CPrivLink* Last();
- FW_CPrivLink* Previous();
- FW_CPrivLink* Current();
- FW_Boolean IsNotComplete();
- void RemoveCurrent();
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- private:
- FW_CPrivLinkedList* fList;
- FW_CPrivLink* fCurrent;
- FW_CPrivLink* fNext; // Used only when deleting while iterating
- FW_CPrivLink* fPrevious; // Used only when deleting while iterating
- FW_CPrivLink* fSentinel;
- unsigned long fSeed; // Used to detect out-of-sync iterators
- };
-
- #endif // FWLIST_H
-