home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
-
- #ifndef _ITBSEQ_H
- #define _ITBSEQ_H
-
- #include <iglobals.h>
- #include <icursor.h>
- #include <iitbseq.h>
-
- template < class Element, class ElementOps >
- class IGTabularSequence {
-
- static ElementOps cvElementOps;
-
- class Node;
- class Operations;
- class Cursor;
-
- friend class Node;
- friend class Operations;
- friend class Cursor;
-
- class Node
- { friend class IGTabularSequence < Element, ElementOps >;
- friend class Cursor;
- friend class Operations;
-
- Element ivElement;
-
- void* operator new (size_t s)
- { return cvElementOps.allocate (s); }
-
- void operator delete (void* p)
- { cvElementOps.deallocate (p); }
- };
-
- class Operations : public ITabularSequenceImpl::Operations
- { friend class IGTabularSequence < Element, ElementOps >;
-
- void swap (INumber index1,
- INumber index2) const;
- void copyFrom (INumber index,
- void const* element) const;
- void const* elementAt (INumber index) const;
-
- Boolean constantFunctionIteration (void *function,
- void* env,
- INumber index) const;
- Boolean functionIteration (void *function,
- void* env,
- INumber index);
- Boolean constantIteratorIteration (void* iterator,
- INumber index) const;
- Boolean iteratorIteration (void* iterator,
- INumber index);
-
- long functionComparison (void *compareFunction,
- void const* element1,
- void const* element2);
- long functionComparison (void *compareFunction,
- INumber index1,
- INumber index2);
-
- void blockLeft (INumber target, INumber moveCount);
- void blockRight (INumber target, INumber moveCount);
-
- void copy (ITabularSequenceImpl::Table const&);
- void expand (INumber n);
- };
-
- // ivOps must be initialized (and therefore declared) before ivImpl
- // since the constructor of ivImpl uses ivOps.
- Operations ivOps;
- ITabularSequenceImpl ivImpl;
-
- public:
-
- class Cursor : public ICursor {
- protected:
- IGTabularSequence < Element, ElementOps > const* ivCollection;
- ITabularSequenceImpl::Cursor ivImpl;
- friend class IGTabularSequence < Element, ElementOps >;
- public:
- Cursor (IGTabularSequence < Element, ElementOps > const& collection)
- : ivCollection (&collection) {};
-
- Boolean setToFirst ();
- Boolean setToNext ();
- Boolean isValid () const;
- void invalidate ();
-
- Element const& element ()
- { return ivCollection->elementAt (*this); }
-
- Boolean setToLast ()
- { return ivCollection->setToLast (*this); }
- Boolean setToPrevious ()
- { return ivCollection->setToPrevious (*this); }
-
- Boolean operator== (Cursor const& cursor)
- { return ivCollection == cursor.ivCollection &&
- ivImpl == cursor.ivImpl; }
- Boolean operator!= (Cursor const& cursor)
- { return ! operator== (cursor); }
- };
-
- public:
-
- IGTabularSequence (INumber
- numberOfElements = 100,
- IBoundIndicator =
- IUnbounded);
-
- IGTabularSequence (IGTabularSequence < Element, ElementOps > const&);
-
- IGTabularSequence < Element, ElementOps >& operator = (IGTabularSequence < Element, ElementOps > const&);
-
- ~IGTabularSequence ();
-
- Boolean add (Element const&);
-
- Boolean add (Element const&,
- ICursor&);
-
- void addAllFrom (IGTabularSequence < Element, ElementOps > const&);
-
- Element const& elementAt (ICursor const&) const;
-
- Element& elementAt (ICursor const&);
-
- Element const& anyElement () const;
-
- void removeAt (ICursor const&);
-
- INumber removeAll (Boolean (*property)
- (Element const&, void*),
- void* additionalArgument = 0);
-
- void replaceAt (ICursor const&,
- Element const&);
-
- void removeAll ();
-
- Boolean isBounded () const;
-
- INumber maxNumberOfElements () const;
-
- INumber numberOfElements () const;
-
- Boolean isEmpty () const;
-
- Boolean isFull () const;
-
- ICursor* newCursor () const;
-
- Boolean setToFirst (ICursor&) const;
-
- Boolean setToNext (ICursor&) const;
-
- Boolean allElementsDo (Boolean (*function)
- (Element&, void*),
- void* additionalArgument = 0);
-
- Boolean allElementsDo (IIterator <Element>&);
-
- Boolean allElementsDo (Boolean (*function)
- (Element const&, void*),
- void* additionalArgument = 0)
- const;
-
- Boolean allElementsDo (IConstantIterator
- <Element>&) const;
-
- void removeFirst ();
-
- void removeLast ();
-
- void removeAtPosition (IPosition);
-
- Element const& firstElement () const;
-
- Element const& lastElement () const;
-
- Element const& elementAtPosition (IPosition) const;
-
- Boolean setToLast (ICursor&) const;
-
- Boolean setToPrevious (ICursor&) const;
-
- void setToPosition (IPosition,
- ICursor&) const;
-
- Boolean isFirst (ICursor const&) const;
-
- Boolean isLast (ICursor const&) const;
-
- long compare (IGTabularSequence < Element, ElementOps > const&,
- long (*comparisonFunction)
- (Element const&,
- Element const&)) const;
-
- void addAsFirst (Element const&);
-
- void addAsFirst (Element const&,
- ICursor&);
-
- void addAsLast (Element const&);
-
- void addAsLast (Element const&,
- ICursor&);
-
- void addAsNext (Element const&,
- ICursor&);
-
- void addAsPrevious (Element const&,
- ICursor&);
-
- void addAtPosition (IPosition,
- Element const&);
-
- void addAtPosition (IPosition,
- Element const&,
- ICursor&);
-
- void sort (long (*comparisonFunction)
- (Element const&,
- Element const&));
-
- protected:
-
- void checkNotEmpty () const;
- void checkCursorIsForThis (ICursor const&) const;
- void checkCursor (ICursor const&) const;
- void checkPositionExists (IPosition) const;
- void checkPositionForAdd (IPosition) const;
- };
-
- template < class Element >
- class ITabularSequence :
- public IGTabularSequence < Element, IStdOps < Element > > {
- public:
- ITabularSequence (INumber n = 100, IBoundIndicator b = IUnbounded) :
- IGTabularSequence < Element, IStdOps < Element > > (n, b) {}
- };
-
- #include <itbseq.if>
-
- #ifdef __IBMCPP__
- #include <itbseq.c>
- #endif
-
- #endif