home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWTISLIST_H__
- #define __RWTISLIST_H__
- pragma push_align_members(64);
-
- /*
- * RWTIsvSlist<T>: Parameterized intrusive list of Ts (which must derive from RWIsvSlink)
- *
- * $Header: E:/vcs/rw/tislist.h_v 1.1 04 Mar 1992 10:16:40 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave Software, Inc.
- * P.O. Box 2328
- * Corvallis, OR 97339
- *
- * Copyright (C) 1992. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/tislist.h_v $
- *
- * Rev 1.1 04 Mar 1992 10:16:40 KEFFER
- *
- *
- * Rev 1.0 02 Mar 1992 16:10:52 KEFFER
- * Initial revision.
- */
-
- //$DECLARE_TEMPLATE
-
- #include "rw/islist.h"
-
-
- /****************************************************************
- * *
- * Declarations for RWTIsvSlist<T> *
- * *
- ****************************************************************/
-
- template <class T> class RWExport RWTIsvSlist : private RWIsvSlist {
-
- friend class RWExport RWTIsvSlistIterator<T>;
- typedef RWIsvSlist BASE;
-
- protected:
-
- RWIsvSlist::_lastSlink; // Adjust visibility to allow access by subclasses
- RWIsvSlist::findLeft;
- RWIsvSlist::insertAfterLink;
- RWIsvSlist::removeRight;
-
- public:
-
- RWTIsvSlist() { }
- RWTIsvSlist(T* a) : RWIsvSlist(a) { }
-
- /********************* Member functions **************************/
- void append(T* a) {BASE::append(a);}
- void apply(void (*applyFun)(T*, void*), void*);
- T* at(int i) const {return (T*)BASE::at(i);}
- RWIsvSlist::clear;
- void clearAndDestroy();
- RWBoolean contains(RWBoolean (*testFun)(const T*, void*), void*) const;
- RWBoolean containsReference(const T* a) const {return BASE::containsReference(a);}
- RWIsvSlist::entries;
- T* find(RWBoolean (*testFun)(const T*, void*), void*) const;
- T* first() const {return (T*)BASE::first();}
- T* get() {return (T*)BASE::get();}
- int index(RWBoolean (*testFun)(const T*, void*), void*) const;
- void insert(T* a) {BASE::append(a);}
- void insertAfter(int i, T* a) {BASE::insertAfter(i,a);}
- void insertAt(int i, T* a) {BASE::insertAt(i,a);}
- RWIsvSlist::isEmpty;
- T* last() const {return (T*)BASE::last();}
- unsigned occurrencesOf(RWBoolean (*testFun)(const T*, void*), void*) const;
- unsigned occurrencesOfReference(const T* a) const{return BASE::occurrencesOfReference(a);}
- void prepend(T* a) {BASE::prepend(a);}
- T* remove(RWBoolean (*testFun)(const T*, void*), void*);
- T* removeAt(int i) {return (T*)BASE::removeAt(i);}
- T* removeFirst() {return (T*)BASE::removeFirst();}
- T* removeLast() {return (T*)BASE::removeLast();}
- T* removeReference(const T* a) {return (T*)BASE::removeReference(a);}
- };
-
- /****************************************************************
- * *
- * Declarations for RWTIsvSlistIterator<T> *
- * *
- ****************************************************************/
-
- template <class T> class RWExport RWTIsvSlistIterator: private RWIsvSlistIterator {
-
- typedef RWIsvSlistIterator BASE;
-
- // Disallow postfix increment. Unless we hide it, some compilers will
- // substitute the prefix increment operator in its place.
- RWBoolean operator++(int);
-
- protected:
-
- RWIsvSlistIterator::_shere; // Allow visibility to subclasses
- RWIsvSlistIterator::_slist;
- RWIsvSlistIterator::removeRight;
-
- public:
-
- // Constructor: starts with iterator positioned at last link.
- RWTIsvSlistIterator(RWTIsvSlist<T>& s) : RWIsvSlistIterator(s) { }
-
- // Operators:
- RWBoolean operator++() {return BASE::operator++();}
- T* operator()() {return (T*)BASE::operator()();}
- RWIsvSlistIterator::operator+=; // Advance iterator n links and test
-
- // Member functions:
- RWTIsvSlist<T>* container() const {return (RWTIsvSlist<T>*)BASE::container();}
- T* findNext(RWBoolean (*testFun)(const T*, void*), void*);
- T* findNextReference(const T* a) {return (T*)BASE::findNextReference(a);}
- void insertAfterPoint(T* a) {BASE::insertAfterPoint(a);}
- T* key() const {return (T*)BASE::key();}
- T* remove() {return (T*)BASE::remove();}
- T* removeNext(RWBoolean (*testFun)(const T*, void*), void*);
- T* removeNextReference(const T* a) {return (T*)BASE::removeNextReference(a);}
- void reset() {BASE::reset();}
- void reset(RWTIsvSlist<T>& s) {BASE::reset(s);}
- };
-
-
- //$IMPLEMENT_TEMPLATE
-
- /****************************************************************
- * *
- * Definitions for RWTIsvSlist<T> *
- * *
- ****************************************************************/
-
- template <class T> void
- RWTIsvSlist<T>::apply(void (*applyFun)(T*, void*), void* p)
- {
- RWIsvSlink* link = _lastSlink;
- if (link) {
- do {
- link = link->next(); // Advance to next link
- (*applyFun)((T*)link, p); // Apply the function
- } while (link != _lastSlink);
- }
- }
-
- template <class T> void
- RWTIsvSlist<T>::clearAndDestroy()
- {
- // First delete all links, then call the base class's clear()
-
- RWIsvSlink* link = _lastSlink;
- if (link) {
- do {
- RWIsvSlink* n = link->next(); // Remember next link
- delete (T*)link; // Delete this link
- link = n; // Advance to next link
- } while (link != _lastSlink);
- }
- RWIsvSlist::clear(); // Call base class clear();
- }
-
- template <class T> RWBoolean
- RWTIsvSlist<T>::contains(RWBoolean (*testFun)(const T*, void*), void* a) const
- {
- // Cast "const" away:
- RWTIsvSlistIterator<T> sc(*(RWTIsvSlist<T>*)this);
- return sc.findNext(testFun, a) != rwnil;
- }
-
- template <class T> T*
- RWTIsvSlist<T>::find(RWBoolean (*testFun)(const T*, void*), void* a) const
- {
- RWTIsvSlistIterator<T> sc(*(RWTIsvSlist<T>*)this);
- return (T*)sc.findNext(testFun, a);
- }
-
- template <class T> int
- RWTIsvSlist<T>::index(RWBoolean (*testFun)(const T*, void*), void* a) const
- {
- int count = -1;
- if (_lastSlink) { // List is not empty.
- register const RWIsvSlink* link = _lastSlink;
- do {
- link = link->next();
- count++;
- if( (*testFun)((T*)link, a) ) return count;
- } while ( link!=_lastSlink );
- count = -1;
- }
- return count;
- }
-
- template <class T> unsigned
- RWTIsvSlist<T>::occurrencesOf(RWBoolean (*testFun)(const T*, void*), void* a) const
- {
- unsigned count = 0;
- RWTIsvSlistIterator<T> sc(*(RWTIsvSlist<T>*)this);
- while (sc.findNext(testFun, a)) count++;
- return count;
- }
-
- template <class T> T*
- RWTIsvSlist<T>::remove(RWBoolean (*testFun)(const T*, void*), void* a)
- {
- RWTIsvSlistIterator<T> sc(*(RWTIsvSlist<T>*)this);
- return sc.removeNext(testFun, a);
- }
-
- /****************************************************************
- * *
- * Definitions for RWTIsvSlistIterator<T> *
- * *
- ****************************************************************/
-
- /*
- * Return first occurrence where the tester returns true.
- */
- template <class T> T*
- RWTIsvSlistIterator<T>::findNext(RWBoolean (*testFun)(const T*, void*), void* a)
- {
- while ( ++(*this) ){
- if ( (*testFun)((const T*)key(), a) ) return key();
- }
- return rwnil;
- }
-
- /*
- * Remove first occurrence where the tester returns true.
- */
- template <class T> T*
- RWTIsvSlistIterator<T>::removeNext(RWBoolean (*testFun)(const T*, void*), void* a)
- {
- T* cur;
- T* prev = key(); // Remember "previous" link
-
- while ( ++(*this) ) { // Advance iterator
- cur = key(); // Get current value
- if ( (*testFun)((const T*)cur, a) ) // Is this the victim?
- return (T*)BASE::removeRight(prev); // If it is, remove it.
- prev = cur;
- }
- return rwnil;
- }
-
- pragma pop_align_members();
- #endif /* __RWTISLIST_H__ */
-