home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IAVLKSS.H
< prev
next >
Wrap
Text File
|
1993-09-22
|
11KB
|
287 lines
/*******************************************************************************
* *
* COPYRIGHT: *
* IBM C/C++ Tools Version 2.01 - Collection Class Library *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IAVLKSS_H
#define _IAVLKSS_H
#include <iglobals.h>
#include <icursor.h>
#include <iiavlkss.h>
template < class Element, class Key, class ElementOps >
class IGAvlKeySortedSet {
static ElementOps elementOps ()
{ ElementOps ops;
return ops;
}
class Node;
class Operations;
class Cursor;
friend class Node;
friend class Operations;
friend class Cursor;
class Node : public IAvlKeySortedSetImpl::Node {
friend class IGAvlKeySortedSet < Element, Key, ElementOps >;
friend class Cursor;
friend class Operations;
Element ivElement;
Node (Element const& element)
: ivElement (element) {};
#if defined (__IBMCPP__) && defined (__DEBUG_ALLOC__)
void* operator new (size_t s, char const* fn, size_t ln)
{ return elementOps().allocate (s, fn, ln); }
void operator delete (void* p, char const* fn, size_t ln)
{ elementOps().deallocate (p, fn, ln); }
#else
void* operator new (size_t s)
{ return elementOps().allocate (s); }
void operator delete (void* p)
{ elementOps().deallocate (p); }
#endif // __IBMCPP__ && __DEBUG_ALLOC__
};
class Operations : public IAvlKeySortedSetImpl::Operations {
IAvlKeySortedSetImpl::Node*
newNode (void const* element) const;
IAvlKeySortedSetImpl::Node*
copyNode (void const* node) const;
void deleteNode (void* node) const;
void* elementAt (void *node) const;
void const* constElementAt (void const* node) const;
void const* keyAt (void const* node) const;
long compareKeyToElement (void const* node,
void const* element) const;
long compareKeyToKey (void const* node,
void const* key) const;
IBoolean isEqualTo (void const* node1,
void const* node2) const;
IBoolean isEqualToElement (void const* node,
void const* element) const;
void copyFrom (void* node,
void const* element) const;
IBoolean constantFunctionIteration (void *function,
void* env,
void const* node);
IBoolean functionIteration (void *function,
void* env,
void* node);
IBoolean constantIteratorIteration (void* iterator,
void const* node);
IBoolean 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;
IAvlKeySortedSetImpl ivImpl;
public:
class Cursor : public ICursor {
protected:
IGAvlKeySortedSet < Element, Key, ElementOps > const* ivCollection;
IAvlKeySortedSetImpl::Node *ivNode;
friend class IGAvlKeySortedSet < Element, Key, ElementOps >;
IBoolean isFor (IGAvlKeySortedSet
< Element, Key, ElementOps > const& c) const
{ return ivCollection == &c; }
public:
Cursor (IGAvlKeySortedSet < Element, Key, ElementOps > const& c)
: ivCollection (&c), ivNode (0) {};
IBoolean setToFirst ();
IBoolean setToNext ();
IBoolean isValid () const;
void invalidate ();
Element const& element () const
{ return ivCollection->elementAt (*this); }
IBoolean setToLast ()
{ return ivCollection->setToLast (*this); }
IBoolean setToPrevious ()
{ return ivCollection->setToPrevious (*this); }
IBoolean operator== (Cursor const& cursor) const
{ return ivCollection == cursor.ivCollection &&
ivNode == cursor.ivNode; }
IBoolean operator!= (Cursor const& cursor) const
{ return ! operator== (cursor); }
};
private:
void checkNotEmpty () const;
void checkCursorIsForThis (ICursor const&) const;
void checkCursor (ICursor const&) const;
void checkPositionExists (IPosition) const;
public:
IGAvlKeySortedSet (INumber
numberOfElements = 100);
IGAvlKeySortedSet (IGAvlKeySortedSet < Element, Key, ElementOps > const&);
IGAvlKeySortedSet < Element, Key, ElementOps >&
operator = (IGAvlKeySortedSet < Element, Key, ElementOps > const&);
~IGAvlKeySortedSet ();
IBoolean add (Element const&);
IBoolean add (Element const&,
ICursor&);
void addAllFrom (IGAvlKeySortedSet < Element, Key, ElementOps > const&);
Element const& elementAt (ICursor const&) const;
Element& elementAt (ICursor const&);
Element const& anyElement () const;
void removeAt (ICursor const&);
INumber removeAll (IBoolean (*property)
(Element const&, void*),
void* additionalArgument = 0);
void replaceAt (ICursor const&,
Element const&);
void removeAll ();
IBoolean isBounded () const;
INumber maxNumberOfElements () const;
INumber numberOfElements () const;
IBoolean isEmpty () const;
IBoolean isFull () const;
ICursor* newCursor () const;
IBoolean setToFirst (ICursor&) const;
IBoolean setToNext (ICursor&) const;
IBoolean allElementsDo (IBoolean (*function)
(Element&, void*),
void* additionalArgument = 0);
IBoolean allElementsDo (IIterator <Element>&);
IBoolean allElementsDo (IBoolean (*function)
(Element const&, void*),
void* additionalArgument = 0)
const;
IBoolean allElementsDo (IConstantIterator
<Element>&) const;
IBoolean isConsistent () const;
Key const& key (Element const&) const;
IBoolean containsElementWithKey (Key const&) const;
IBoolean containsAllKeysFrom (IGAvlKeySortedSet < Element, Key, ElementOps > const&) const;
IBoolean locateElementWithKey (Key const&, ICursor&)
const;
IBoolean replaceElementWithKey (Element const&);
IBoolean replaceElementWithKey (Element const&,
ICursor&);
IBoolean locateOrAddElementWithKey (Element const&);
IBoolean locateOrAddElementWithKey (Element const&,
ICursor&);
IBoolean addOrReplaceElementWithKey (Element const&);
IBoolean addOrReplaceElementWithKey (Element const&,
ICursor&);
IBoolean removeElementWithKey (Key const&);
Element const& elementWithKey (Key const&) const;
Element& elementWithKey (Key const&);
void removeFirst ();
void removeLast ();
void removeAtPosition (IPosition);
Element const& firstElement () const;
Element const& lastElement () const;
Element const& elementAtPosition (IPosition) const;
IBoolean setToLast (ICursor&) const;
IBoolean setToPrevious (ICursor&) const;
void setToPosition (IPosition,
ICursor&) const;
IBoolean isFirst (ICursor const&) const;
IBoolean isLast (ICursor const&) const;
long compare (IGAvlKeySortedSet < Element, Key, ElementOps > const&,
long (*comparisonFunction)
(Element const&,
Element const&)) const;
};
#include <iavlkss.if>
template < class Element, class Key >
class IAvlKeySortedSet :
public IGAvlKeySortedSet < Element, Key, IKCOps < Element, Key > > {
public:
IAvlKeySortedSet (INumber n = 100) :
IGAvlKeySortedSet < Element, Key, IKCOps < Element, Key > > (n) {}
};
#ifdef __IBMCPP__
#ifndef __TEMPINC__
#include <iavlkss.c>
#endif
#endif
#endif