home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IHSHKS.H
< prev
next >
Wrap
Text File
|
1993-09-22
|
10KB
|
254 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 _IHSHKS_H
#define _IHSHKS_H
#include <iglobals.h>
#include <icursor.h>
#include <stdlib.h>
#include <iihshkb.h>
template < class Element, class Key, class ElementOps >
class IGHashKeySet {
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 IHashKeyBagImpl::Node {
friend class IGHashKeySet < 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 IHashKeyBagImpl::Operations {
IHashKeyBagImpl::Node*
newNode (void const* element) const;
IHashKeyBagImpl::Node*
copyNode (void const* node) const;
void deleteNode (void* node) const;
void* newBlock (size_t size) const;
void removeBlock (void*, size_t size) const;
INumber getHashvalue (void const* key, INumber) const;
void* elementAt (void *node) const;
void const* keyAt (void const* node) const;
IBoolean isKeyEqualToElement (void const* node,
void const* element) const;
IBoolean isKeyEqualToKey (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);
};
// ivOps must be initialized (and therefore declared) before ivImpl
// since the constructor of ivImpl uses ivOps.
Operations ivOps;
IHashKeyBagImpl ivImpl;
public:
class Cursor : public ICursor {
protected:
IGHashKeySet < Element, Key, ElementOps > const* ivCollection;
IHashKeyBagImpl::Cursor ivImpl;
friend class IGHashKeySet < Element, Key, ElementOps >;
IBoolean isFor (IGHashKeySet < Element, Key, ElementOps > const& c) const
{ return ivCollection == &c; }
public:
Cursor (IGHashKeySet < Element, Key, ElementOps > const& c)
: ivCollection (&c) {};
IBoolean setToFirst ();
IBoolean setToNext ();
IBoolean isValid () const;
void invalidate ();
Element const& element () const
{ return ivCollection->elementAt (*this); }
IBoolean operator== (Cursor const& cursor) const
{ return ivCollection == cursor.ivCollection &&
ivImpl == cursor.ivImpl; }
IBoolean operator!= (Cursor const& cursor) const
{ return ! operator== (cursor); }
};
private:
void checkNotEmpty () const;
void checkCursorIsForThis (ICursor const&) const;
void checkCursor (ICursor const&) const;
public:
IGHashKeySet (INumber
numberOfElements = 100);
IGHashKeySet (IGHashKeySet < Element, Key, ElementOps > const&);
IGHashKeySet < Element, Key, ElementOps >&
operator = (IGHashKeySet < Element, Key, ElementOps > const&);
~IGHashKeySet ();
IBoolean add (Element const&);
IBoolean add (Element const&,
ICursor&);
void addAllFrom (IGHashKeySet < 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 (IGHashKeySet < 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&);
};
template < class Element, class Key >
class IHashKeySet :
public IGHashKeySet < Element, Key, IKEHOps < Element, Key > > {
public:
IHashKeySet (INumber n = 100) :
IGHashKeySet < Element, Key, IKEHOps < Element, Key > > (n) {}
};
#include <ihshks.if>
#ifdef __IBMCPP__
#ifndef __TEMPINC__
#include <ihshks.c>
#endif
#endif
#endif