home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWORDCLTN_H__
- #define __RWORDCLTN_H__
- pragma push_align_members(64);
-
- /*
- * RWOrdered --- Ordered Collection
- *
- * $Header: E:/vcs/rw/ordcltn.h_v 1.7 17 Mar 1992 19:21:10 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.
- *
- ***************************************************************************
- *
- * The copy constructor and assignment operator use memberwise
- * initialization and assignment, respectively.
- *
- * $Log: E:/vcs/rw/ordcltn.h_v $
- *
- * Rev 1.7 17 Mar 1992 19:21:10 KEFFER
- * Changed BOUNDS_CHECK to RWBOUNDS_CHECK
- *
- * Rev 1.6 04 Mar 1992 09:03:52 KEFFER
- * nil changed to rwnil
- *
- * Rev 1.5 18 Feb 1992 09:54:32 KEFFER
- *
- * Rev 1.4 05 Nov 1991 13:52:06 keffer
- * Now declares GVector of RWCollectableP, instead of relying on collect.h
- *
- * Rev 1.3 28 Oct 1991 09:08:18 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- * Rev 1.2 20 Aug 1991 18:53:12 keffer
- * pop() now returns nitems-1
- *
- * Rev 1.1 29 Jul 1991 14:13:56 keffer
- * Added member function data().
- *
- * Rev 1.0 28 Jul 1991 08:15:54 keffer
- * Tools.h++ V4.0.5 PVCS baseline version
- *
- */
-
- #include "rw/seqcltn.h"
- #include "rw/iterator.h"
- #include "rw/gvector.h"
- declare(GVector,RWCollectableP)
-
- class RWExport RWOrdered : public RWSequenceable {
- friend class RWExport RWOrderedIterator;
- protected:
- unsigned nitems;
- GVector(RWCollectableP) vec; // An array of pointers to objects.
- protected:
- void boundsCheck(int) const;
- RWCollectable* removeAt(unsigned);
- public:
-
- RWOrdered(unsigned size = RWCollection::DEFAULT_CAPACITY);
-
- /******************** Member operators ****************************/
- RWBoolean operator==(const RWOrdered&) const;
-
- /****************** Virtual member functions *******************/
- virtual RWCollectable* append(RWCollectable* a);
- virtual void apply(RWapplyCollectable, void*);
- virtual RWCollectable*& at(int); // Can use as lvalue
- #ifdef CONST_OVERLOADS
- virtual const RWCollectable* at(int) const; // Cannot use as lvalue.
- #endif
- virtual void clear();
- //virtual void clearAndDestroy();
- //virtual RWBoolean contains(const RWCollectable*) const;
- virtual unsigned entries() const {return nitems;}
- virtual RWCollectable* find(const RWCollectable*) const; // First occurrence
- virtual RWCollectable* first() const;
- virtual int index(const RWCollectable*) const; // Returns -1 if not found.
- virtual RWCollectable* insert(RWCollectable*); // Appends.
- virtual RWCollectable* insertAfter(int, RWCollectable*); // Use -1 to insert at beginning
- virtual ClassID isA() const {return __RWORDERED;}
- virtual RWBoolean isEmpty() const {return nitems==0;}
- virtual RWCollectable* last() const;
- virtual RWCollectable* newSpecies() const;
- virtual unsigned occurrencesOf(const RWCollectable*) const;
- virtual RWCollectable* remove(const RWCollectable*); // Remove first occurrence
- //virtual void removeAndDestroy(const RWCollectable*);
- virtual RWCollectable* prepend(RWCollectable*);
-
- /*********************** Special functions ******************************/
- RWCollectable*& operator[](int); // With bounds checking
- RWCollectable*& operator()(int); // Optional bounds checking
- #ifdef CONST_OVERLOADS
- RWCollectable* operator[](int) const; // With bounds checking
- RWCollectable* operator()(int) const; // Optional bounds checking
- #endif
- const RWCollectableP* data() const; // Use with care.
- void push(RWCollectable*); // Alternative stack.
- RWCollectable* pop();
- void resize(unsigned); // Cannot shrink below population
- RWCollectable* top() const;
- };
-
- class RWExport RWOrderedIterator : public RWIterator {
- const RWOrdered* theCollection;
- int here;
- public:
- RWOrderedIterator(const RWOrdered& ord) { theCollection=⩝ here=-1;}
- virtual RWCollectable* findNext(const RWCollectable*); // Find next matching item
- virtual RWCollectable* key() const; // Return current key
- virtual RWCollectable* operator()(); // Advance iterator
- virtual void reset() {here=-1;}
- };
-
- /************************ INLINES *******************************/
- inline RWCollectable*&
- RWOrdered::operator[](int i)
- { boundsCheck(i); return vec(i); }
-
- inline RWCollectable*&
- RWOrdered::operator()(int i)
- {
- #ifdef RWBOUNDS_CHECK
- boundsCheck(i);
- #endif
- return vec(i);
- }
-
- #ifdef CONST_OVERLOADS
- inline RWCollectable*
- RWOrdered::operator[](int i) const
- { boundsCheck(i); return vec(i); }
-
- inline RWCollectable*
- RWOrdered::operator()(int i) const
- {
- #ifdef RWBOUNDS_CHECK
- boundsCheck(i);
- #endif
- return vec(i);
- }
- #endif /* CONST_OVERLOADS */
-
- inline const RWCollectableP*
- RWOrdered::data() const
- {
- return vec.data();
- }
-
- inline void
- RWOrdered::push(RWCollectable* c)
- { insert(c); }
-
- inline RWCollectable*
- RWOrdered::pop()
- { return nitems>0 ? removeAt(nitems-1) : rwnil; }
-
- inline RWCollectable*
- RWOrdered::top() const
- { return nitems>0 ? vec(nitems-1) : rwnil; }
-
- pragma pop_align_members();
- #endif /* __RWORDCLTN_H__ */
-