home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
- #include <ibexcept.h>
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- checkNotEmpty () const
- {
- #ifndef INO_CHECKS
- ICHECK (!isEmpty (), IEmptyException, "collection is empty")
- #endif
- }
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- checkCursorIsForThis (ICursor const& c) const
- {
- #ifndef INO_CHECKS
- ICHECK (((Cursor const&)c).ivCollection == this, ICursorInvalidException,
- "cursor not for this collection")
- #endif
- }
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- checkCursor (ICursor const& c) const
- {
- #ifndef INO_CHECKS
- ICHECK (((Cursor const&)c).ivCollection == this, ICursorInvalidException,
- "cursor not for this collection")
- ICHECK (c.isValid (), ICursorInvalidException, "invalid cursor")
- #endif
- #ifdef IALL_CHECKS
- ICHECK (ivImpl.checkNode(((Cursor const&)c).ivNode),
- ICursorInvalidException, "cursor not contained in collection")
- #endif
- }
-
- template < class Element, class Key, class ElementOps >
- inline IGHashKeyBag < Element, Key, ElementOps >::
- IGHashKeyBag (INumber n, IBoundIndicator b)
- : ivImpl(n, &ivOps) {
- }
-
- template < class Element, class Key, class ElementOps >
- inline IGHashKeyBag < Element, Key, ElementOps >::
- IGHashKeyBag (IGHashKeyBag < Element, Key, ElementOps > const& h)
- : ivImpl(h.ivImpl, &ivOps) {
- }
-
- template < class Element, class Key, class ElementOps >
- inline IGHashKeyBag < Element, Key, ElementOps >::
- ~IGHashKeyBag () {
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- add (Element const& d, ICursor& c)
- { return ivImpl.add
- (&d,
- cvElementOps.keyOps.hash(cvElementOps.key(d), ivImpl.noEntries()),
- ((Cursor&)c).ivImpl
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- add (Element const& d)
- { return ivImpl.add
- (&d,
- cvElementOps.keyOps.hash(cvElementOps.key(d), ivImpl.noEntries())
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- addAllFrom (IGHashKeyBag < Element, Key, ElementOps > const& h)
- {
- #ifndef INO_CHECKS
- ICHECK (this != &h,
- IIdenticalCollectionException, "identical collection in addAllFrom")
- #endif
- ivImpl.addAllFrom(h.ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline IGHashKeyBag < Element, Key, ElementOps >&
- IGHashKeyBag < Element, Key, ElementOps >::
- operator = (IGHashKeyBag < Element, Key, ElementOps > const& h)
- { ivImpl = h.ivImpl;
- return *this;
- }
-
- template < class Element, class Key, class ElementOps >
- inline Element const& IGHashKeyBag < Element, Key, ElementOps >::
- elementAt (ICursor const& c) const
- { checkCursor(c);
- return *(Element const*) ivImpl.elementAt(((Cursor const&)c).ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Element& IGHashKeyBag < Element, Key, ElementOps >::
- elementAt (ICursor const& c)
- { checkCursor(c);
- return *(Element*) ivImpl.elementAt(((Cursor const&)c).ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Element const& IGHashKeyBag < Element, Key, ElementOps >::
- anyElement () const
- { checkNotEmpty();
- return *(Element const*) ivImpl.anyElement();
- }
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- removeAt (ICursor const& c)
- { checkCursor(c);
- ivImpl.removeAt(((Cursor&)c).ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline INumber IGHashKeyBag < Element, Key, ElementOps >::
- removeAll (Boolean (*predicate) (Element const&, void*), void* env)
- { return ivImpl.removeAll (predicate, env);
- }
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- replaceAt (ICursor const& c, Element const& d)
- { checkCursor(c);
- ivImpl.replaceAt(((Cursor const&)c).ivImpl, &d);
- }
-
- template < class Element, class Key, class ElementOps >
- inline void IGHashKeyBag < Element, Key, ElementOps >::
- removeAll ()
- { ivImpl.removeAll();
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- isBounded () const
- { return ivImpl.isBounded();
- }
-
- template < class Element, class Key, class ElementOps >
- inline INumber IGHashKeyBag < Element, Key, ElementOps >::
- maxNumberOfElements () const
- { ICHECK (False, INotBoundedException,
- "maxNumberOfElements is undefined for unbounded collection")
- return 0;
- }
-
- template < class Element, class Key, class ElementOps >
- inline INumber IGHashKeyBag < Element, Key, ElementOps >::
- numberOfElements () const
- { return ivImpl.numberOfElements();
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- isEmpty () const
- { return ivImpl.isEmpty();
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- isFull () const
- { return ivImpl.isFull();
- }
-
- template < class Element, class Key, class ElementOps >
- inline ICursor* IGHashKeyBag < Element, Key, ElementOps >::
- newCursor () const
- { return new Cursor (*this);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- setToFirst (ICursor& c) const
- { return ivImpl.setToFirst(((Cursor&)c).ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- setToNext (ICursor& c) const
- { checkCursor(c);
- return ivImpl.setToNext(((Cursor&)c).ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- allElementsDo (Boolean (*iterationFunction) (Element const&, void*),
- void* env) const {
- return ivImpl.allElementsDo (iterationFunction, env);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- allElementsDo (Boolean (*iterationFunction) (Element&, void*), void* env)
- { return ivImpl.allElementsDo (iterationFunction, env);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- allElementsDo (IConstantIterator <Element>& iterator) const
- { return ivImpl.allElementsDo (&iterator);
- }
-
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- allElementsDo (IIterator <Element>& iterator)
- { return ivImpl.allElementsDo (&iterator);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Key const& IGHashKeyBag < Element, Key, ElementOps >::
- key (Element const& element) const
- { return cvElementOps.key (element);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- containsElementWithKey (Key const& k) const
- { return ivImpl.containsElementWithKey
- (&k,
- cvElementOps.keyOps.hash(k, ivImpl.noEntries())
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- containsAllKeysFrom (IGHashKeyBag < Element, Key, ElementOps > const& h) const
- { return ivImpl.containsAllKeysFrom(h.ivImpl);
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- locateElementWithKey (Key const& k, ICursor& c) const
- { checkCursorIsForThis(c);
- return ivImpl.locateElementWithKey
- (&k,
- cvElementOps.keyOps.hash(k, ivImpl.noEntries()),
- ((Cursor&)c).ivImpl
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- replaceElementWithKey (Element const& d, ICursor& c)
- { checkCursorIsForThis(c);
- return ivImpl.replaceElementWithKey
- (&d,
- cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries()),
- ((Cursor&)c).ivImpl
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- replaceElementWithKey (Element const& d)
- { return ivImpl.replaceElementWithKey
- (&d,
- cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries())
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- locateOrAddElementWithKey (Element const& d, ICursor& c)
- { checkCursorIsForThis(c);
- return ivImpl.locateOrAddElementWithKey
- (&d,
- cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries()),
- ((Cursor&)c).ivImpl
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- locateOrAddElementWithKey (Element const& d)
- { return ivImpl.locateOrAddElementWithKey
- (&d,
- cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries())
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- addOrReplaceElementWithKey (Element const& d, ICursor& c)
- { checkCursorIsForThis(c);
- return ivImpl.addOrReplaceElementWithKey
- (&d,
- cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries()),
- ((Cursor&)c).ivImpl
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- addOrReplaceElementWithKey (Element const& d)
- { return ivImpl.addOrReplaceElementWithKey
- (&d,
- cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries())
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- removeElementWithKey (Key const& k)
- { return ivImpl.removeElementWithKey
- (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
- }
-
- template < class Element, class Key, class ElementOps >
- inline Element const& IGHashKeyBag < Element, Key, ElementOps >::
- elementWithKey (Key const& k) const
- { return *(Element const*) ivImpl.elementWithKey
- (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
- }
-
- template < class Element, class Key, class ElementOps >
- inline Element& IGHashKeyBag < Element, Key, ElementOps >::
- elementWithKey (Key const& k)
- { return *(Element*) ivImpl.elementWithKey
- (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
- }
-
- template < class Element, class Key, class ElementOps >
- inline INumber IGHashKeyBag < Element, Key, ElementOps >::
- numberOfElementsWithKey (Key const& k) const
- { return ivImpl.numberOfElementsWithKey
- (&k,
- cvElementOps.keyOps.hash(k, ivImpl.noEntries())
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- locateNextElementWithKey (Key const& k, ICursor& c) const
- { checkCursor(c);
- return ivImpl.locateNextElementWithKey
- (&k,
- cvElementOps.keyOps.hash(k, ivImpl.noEntries()),
- ((Cursor&)c).ivImpl
- );
- }
-
- template < class Element, class Key, class ElementOps >
- inline INumber IGHashKeyBag < Element, Key, ElementOps >::
- removeAllElementsWithKey (Key const& k)
- { return ivImpl.removeAllElementsWithKey
- (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
- }
-
- template < class Element, class Key, class ElementOps >
- inline INumber IGHashKeyBag < Element, Key, ElementOps >::
- numberOfDifferentKeys() const
- { return ivImpl.numberOfDifferentKeys ();
- }
-
- template < class Element, class Key, class ElementOps >
- inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
- setToNextWithDifferentKey (ICursor& c) const
- { return ivImpl.setToNextWithDifferentKey (((Cursor&)c).ivImpl);
- }