home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
-
- #ifndef _ILNSEQ_H
- #define _ILNSEQ_H
-
- #include <iglobals.h>
- #include <icursor.h>
- #include <iilnseq.h>
-
- template < class Element, class ElementOps >
- class IGLinkedSequence {
-
- static ElementOps cvElementOps;
-
- class Node;
- class Operations;
- class Cursor;
-
- friend class Node;
- friend class Operations;
- friend class Cursor;
-
- class Node : public ILinkedSequenceImpl::Node
- { friend class IGLinkedSequence < Element, ElementOps >;
- friend class Cursor;
- friend class Operations;
-
- Element ivElement;
- Node (Element const& element)
- : ivElement (element) {};
-
- void* operator new (size_t s)
- { return cvElementOps.allocate (s); }
-
- void operator delete (void* p)
- { cvElementOps.deallocate (p); }
- };
-
- class Operations : public ILinkedSequenceImpl::Operations
- { ILinkedSequenceImpl::Node*
- newNode (void const* node) const;
- void deleteNode (void* node) const;
-
- Boolean constantFunctionIteration (void *function,
- void* env,
- void const* node);
- Boolean functionIteration (void *function,
- void* env,
- void* node);
- Boolean constantIteratorIteration (void* iterator,
- void const* node);
- Boolean iteratorIteration (void* iterator,
- void* node);
-
- long functionComparison (void *compareFunction,
- void const* node1,
- void const* node2);
- };
-
- // ivOps must be initialized (and therefore declared) before ivImpl
- // since the constructor of ivImpl uses ivOps.
- Operations ivOps;
- ILinkedSequenceImpl ivImpl;
-
- public:
-
- class Cursor : public ICursor
- {
- protected:
- IGLinkedSequence < Element, ElementOps > const* ivCollection;
- ILinkedSequenceImpl::Node *ivNode;
- friend class IGLinkedSequence < Element, ElementOps >;
- public:
- Cursor (IGLinkedSequence < Element, ElementOps > const& collection)
- : ivCollection (&collection), ivNode (0) {};
-
- 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 &&
- ivNode == cursor.ivNode; }
- Boolean operator!= (Cursor const& cursor)
- { return ! operator== (cursor); }
- };
-
- public:
-
- IGLinkedSequence (INumber
- numberOfElements = 100,
- IBoundIndicator =
- IUnbounded);
-
- IGLinkedSequence (IGLinkedSequence < Element, ElementOps > const&);
-
- IGLinkedSequence < Element, ElementOps >& operator = (IGLinkedSequence < Element, ElementOps > const&);
-
- ~IGLinkedSequence ();
-
- Boolean add (Element const&);
-
- Boolean add (Element const&,
- ICursor&);
-
- void addAllFrom (IGLinkedSequence < 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 (IGLinkedSequence < 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 ILinkedSequence :
- public IGLinkedSequence < Element, IStdOps < Element > > {
- public:
- ILinkedSequence (INumber n = 100, IBoundIndicator b = IUnbounded) :
- IGLinkedSequence < Element, IStdOps < Element > > (n, b) {}
- };
-
- #include <ilnseq.if>
-
- #ifdef __IBMCPP__
- #include <ilnseq.c>
- #endif
-
- #endif