home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWISLIST_H__
- #define __RWISLIST_H__
- pragma push_align_members(64);
-
- /*
- * RWIsvSlist: An intrusive singly-linked list.
- *
- * $Header: E:/vcs/rw/islist.h_v 1.0 11 Mar 1992 14:10:44 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991, 1992. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * See Stroustrup II, Section 8.3.1 for a guide to intrusive lists.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/islist.h_v $
- *
- * Rev 1.0 11 Mar 1992 14:10:44 KEFFER
- * Initial revision.
- *
- */
-
- #include "rw/islink.h"
-
- /****************************************************************
- * *
- * Declarations for RWIsvSlist *
- * *
- ****************************************************************/
-
- class RWExport RWIsvSlist {
- friend class RWExport RWIsvSlistIterator;
- friend class RWExport RWIsvDlistIterator;
-
- protected:
-
- union RWExport {
- RWIsvSlink* _lastSlink; // _lastSlink->_nextSlink is head of list
- RWIsvDlink* _lastDlink;
- };
- unsigned _nitems; // Number of entries in the list
-
- protected:
-
- RWIsvSlink* findLeft(const RWIsvSlink*) const;
- void insertAfterLink(RWIsvSlink*,RWIsvSlink*);
- RWIsvSlink* removeRight(RWIsvSlink*); // Remove and return link after the argument
-
- private:
-
- /* Copies of intrusive lists are dangerous. The following two functions
- are private to disallow copies. */
- RWIsvSlist(const RWIsvSlist&);
- void operator=(const RWIsvSlist& s);
-
- public:
-
- RWIsvSlist() {_lastSlink=rwnil; _nitems=0;}
- RWIsvSlist(RWIsvSlink* a);
- ~RWIsvSlist() {clear();}
-
- /********************* Member functions **************************/
- void append(RWIsvSlink* a) {insertAfterLink(_lastSlink, a);}
- RWIsvSlink* at(int) const; // Return nil if out of range
- void clear();
- RWBoolean containsReference(const RWIsvSlink*) const;
- unsigned entries() const {return _nitems;}
- RWIsvSlink* first() const; // Return link at head of list
- RWIsvSlink* get() {return removeRight(_lastSlink);}
- void insert(RWIsvSlink* a) {append(a);}
- void insertAfter(int, RWIsvSlink*);
- void insertAt(int, RWIsvSlink*);
- RWBoolean isEmpty() const;
- RWIsvSlink* last() const {return _lastSlink;}
- unsigned occurrencesOfReference(const RWIsvSlink*) const;
- void prepend(RWIsvSlink*);
- RWIsvSlink* removeAt(int); // Relatively slow
- RWIsvSlink* removeFirst() {return removeRight(_lastSlink);}
- RWIsvSlink* removeLast(); // Remove and return last link (slow)
- RWIsvSlink* removeReference(const RWIsvSlink* a); // Return and remove the link with address "a"
- };
-
-
-
- /****************************************************************
- * *
- * Declarations for RWIsvSlistIterator *
- * *
- ****************************************************************/
-
- // Iterator for singly linked list:
-
- class RWExport RWIsvSlistIterator {
-
- // Disallow postfix increment. Unless we hide it, some compilers will
- // substitute the prefix increment operator in its place.
- RWBoolean operator++(int);
-
- protected:
-
- union {
- RWIsvSlist* _slist; // The list over which we are iterating
- RWIsvDlist* _dlist;
- };
- union {
- RWIsvSlink* _shere; // Iterator position
- RWIsvDlink* _dhere;
- };
-
- protected:
-
- void resetHere();
- RWIsvSlink* removeRight(RWIsvSlink*); // Remove link to right of given link
-
- public:
-
- // Constructor: starts with iterator positioned at last link.
- RWIsvSlistIterator(RWIsvSlist& s);
-
- // Operators:
- RWBoolean operator++(); // Advance iterator one link and test.
- RWBoolean operator+=(int n); // Advance iterator n links and test.
- RWIsvSlink* operator()(); // Advance, test, and return. For lateral compatibility
-
- RWIsvSlist* container() const {return _slist;}
- RWIsvSlink* findNextReference(const RWIsvSlink*);
- void insertAfterPoint(RWIsvSlink*);// Insert item after position.
- RWIsvSlink* key() const; // Return current item
- RWIsvSlink* remove(); // Remove current item (slow)
- RWIsvSlink* removeNextReference(const RWIsvSlink*);
- void reset();
- void reset(RWIsvSlist&); // Reset container to be interated over.
- };
-
- /************************ RWIsvSlist inlines ******************************/
-
- inline RWBoolean
- RWIsvSlist::isEmpty() const {return _lastSlink==rwnil;}
-
- // Return link at head of list
- inline RWIsvSlink*
- RWIsvSlist::first() const
- { return _lastSlink==rwnil ? rwnil : _lastSlink->_nextSlink; }
-
- /*********************** RWIsvSlistIterator inlines *****************************/
-
- // Reset iterator: position it to the "last" link.
- // This will be nil if the list is empty.
- inline void
- RWIsvSlistIterator::reset()
- { _shere = _slist->_lastSlink; }
-
- // Constructor: start with iterator positioned at last link
- inline
- RWIsvSlistIterator::RWIsvSlistIterator(RWIsvSlist& s) :
- _slist(&s)
- { reset(); }
-
- pragma pop_align_members();
- #endif /* __RWISLIST_H__ */
-