home *** CD-ROM | disk | FTP | other *** search
- #ifndef _RWSLIST_H__
- #define _RWSLIST_H__
- pragma push_align_members(64);
-
- /*
- * Declarations for Singly-linked lists.
- *
- * $Header: E:/vcs/rw/slist.h_v 1.3 04 Mar 1992 09:04:52 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/slist.h_v $
- *
- * Rev 1.3 04 Mar 1992 09:04:52 KEFFER
- * nil changed to rwnil
- *
- * Rev 1.2 18 Feb 1992 09:54:44 KEFFER
- *
- * Rev 1.1 28 Oct 1991 09:08:24 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- * Rev 1.0 28 Jul 1991 08:17:00 keffer
- * Tools.h++ V4.0.5 PVCS baseline version
- *
- */
-
- /*
- * Singly linked list of pointers to voids.
- *
- * See e.g., B. Stroustrup, The C++ Programming Language, Addison-Wesley,
- * Reading, Mass., 1986; 328pp. (ISBN 0-201-12078-X) p.203
- */
-
- #include "rw/tooldefs.h"
- #include "rw/mempool.h"
- STARTWRAP
- #include <stddef.h>
- ENDWRAP
-
- class RWExport RWDlink;
-
- // Single link:
-
- class RWExport RWSlink : public RWMemoryPool {
- friend class RWExport RWSlist;
- friend class RWExport RWDlist;
- friend class RWExport RWSlistIterator;
- friend class RWExport RWDlistIterator;
- protected:
- union RWExport {
- RWSlink* nextSlink; // Pointer to next link.
- RWDlink* nextDlink;
- };
- void* e; // Pointer to void.
-
- RWSlink(void* a, RWSlink* n) { e=a; nextSlink=n; } // Private constructor.
- };
-
- class RWExport RWSlist {
- friend class RWExport RWSlistIterator;
- friend class RWExport RWDlistIterator;
- protected:
- union RWExport {
- RWSlink* lastSlink; // lastSlink->nextSlink is head of list
- RWDlink* lastDlink;
- };
- protected:
- void boundsErr(int) const;
- void deleteRight(RWSlink*);
- RWSlink* findLeft(RWSlink*) const;
- RWSlink* findLink(int) const;
- void insertAfterLink(RWSlink*, void*);
- public:
- RWSlist() {lastSlink=rwnil;}
- RWSlist(void* a);
- RWSlist(const RWSlist&);
- ~RWSlist() {clear();}
- void operator=(const RWSlist& s);
-
- /********************* Member functions **************************/
- void* append(void*); // Add at tail of list.
- void apply(RWapplyGeneric, void*);
- void*& at(int); // Error if out of range.
- #ifdef CONST_OVERLOADS
- const void* at(int) const; // Returns nil if out of range.
- #endif
- void clear();
- RWBoolean contains(RWtestGeneric, const void*) const;
- RWBoolean containsReference(const void*) const;
- unsigned entries() const; // Total entries
- void* find(RWtestGeneric, const void*) const;
- void* findReference(const void*) const; // First occurrence
- void* first() const; // Return value at head of list
- void* get(); // Return value and delete link at head of list
- int index(RWtestGeneric, const void*) const;
- void* insert(void* a) {return RWSlist::append(a);}
- void* insertAfter(int, void*);
- RWBoolean isEmpty() const;
- void* last() const; // Return value at tail of list
- unsigned occurrencesOf(RWtestGeneric, const void*) const;
- unsigned occurrencesOfReference(const void*) const;
- void* prepend(void*);
- void* remove(RWtestGeneric, const void*);
- void* removeReference(const void*);
- };
-
- // Iterator for singly linked list (moves iterator through the list):
- class RWExport RWSlistIterator {
- protected:
- union RWExport {
- RWSlist* slist;
- RWDlist* dlist;
- };
- union RWExport {
- RWSlink* shere; // Iterator position
- RWDlink* dhere;
- };
- protected:
- void resetHere();
- RWSlink* currentLink() const {return shere ? shere : slist->lastSlink;}
- public:
- // Constructor: starts with iterator positioned at last link.
- RWSlistIterator(RWSlist& s);
-
- void operator++(); // Advance iterator one link.
- void operator+=(int n); // Advance iterator n links.
-
- RWBoolean atFirst() const; // Is iterator at head of list?
- RWBoolean atLast() const; // Is iterator at end of list?
- void* findNext(RWtestGeneric, const void*);
- void* findNextReference(const void*);
- void* insertAfterPoint(void*);// Insert item after position.
- void* key() const; // Return current item
- void* operator()(); // Advance iterator
- void* remove(); // Remove current item
- void* removeNext(RWtestGeneric, const void*);
- void* removeNextReference(const void*);
- void reset();
- void toFirst(); // Move iterator to start of list.
- void toLast(); // Move iterator to end of list.
- };
-
- /************************ RWSlist inlines ******************************/
-
- Inline RWBoolean
- RWSlist::isEmpty() const {return lastSlink==rwnil;}
-
- // Return value at head of list
- Inline void*
- RWSlist::first() const
- { return isEmpty() ? rwnil : lastSlink->nextSlink->e ; }
-
- // Return value at tail of list
- Inline void*
- RWSlist::last() const
- { return isEmpty() ? rwnil : lastSlink->e ; }
-
-
- /*********************** RWSlistIterator inlines *****************************/
-
- // Constructor: start with iterator positioned at last link
- Inline
- RWSlistIterator::RWSlistIterator(RWSlist& s) { slist = &s; reset(); }
-
- Inline void
- RWSlistIterator::toLast() {reset();}
-
- Inline RWBoolean
- RWSlistIterator::atLast() const {return shere==slist->lastSlink;}
-
- Inline RWBoolean
- RWSlistIterator::atFirst() const {return shere==slist->lastSlink->nextSlink;}
-
- pragma pop_align_members();
- #endif /* __RWSLIST_H__ */
-