home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
- *
- * (c) Westmount Technology 1994
- *
- * File: @(#)WmtRWTPSetDict.hxx /main/titanic/2
- * Author: peku
- * Description: pointer set dictionary based on RogueWave library
- *---------------------------------------------------------------------------
- SccsId = @(#)WmtRWTPSetDict.hxx /main/titanic/2 12 Nov 1997 Copyright 1994 Westmount Technology */
-
- #ifndef WMTRWTPSETDICT_HXX
- #define WMTRWTPSETDICT_HXX
-
- #ifndef __RWTVHDICT_H__
- #include "rw/tvhdict.h"
- #endif
-
- #ifndef WMTRWTPTRSET_HXX
- #include "WmtRWTPtrSet.hxx"
- #endif
-
- template<class K, class V>
- class WmtRWTPSetDict : private RWTValHashDictionary<K, WmtRWTPtrSet<V>* > {
- public:
- WmtRWTPSetDict(unsigned (*hashKey)(const K&)) :
- RWTValHashDictionary<K, WmtRWTPtrSet<V>* >(hashKey)
- {
- }
- RWBoolean doFindValue(const K& key, WmtRWTPtrSet<V>* &retval) const
- {
- if (! RWTValHashDictionary<K, WmtRWTPtrSet<V>* >::findValue(
- key, retval)) {
- return FALSE;
- } else {
- return TRUE;
- }
- }
- void doInsertKeyAndValue(const K& key, V *val)
- {
- if (! RWTValHashDictionary<K, WmtRWTPtrSet<V>* >::contains(key)) {
- RWTValHashDictionary<K, WmtRWTPtrSet<V>* >::insertKeyAndValue(
- key, new WmtRWTPtrSet<V>);
- }
- WmtRWTPtrSet<V> *set;
- RWTValHashDictionary<K, WmtRWTPtrSet<V>* >::findValue(key, set);
- set->doInsert(val);
- }
- RWBoolean doRemoveKeyAndValue(const K& key, V *val)
- {
- WmtRWTPtrSet<V> *set;
- if (doFindValue(key, set)) {
- set->doRemove(val);
- if (set->doIsEmpty()) {
- RWTValHashDictionary<K, WmtRWTPtrSet<V>* >::remove(key);
- delete set;
- }
- return TRUE;
- } else {
- return FALSE;
- }
- }
- //void doClear()
- // { RWTValHashDictionary<K, WmtRWTPtrSet<V>* >::clear(); }
- };
-
- template <class K, class V>
- class WmtRWTPSetDictIterator :
- private RWTValHashDictionaryIterator<K, WmtRWTPtrSet<V>* > {
- public:
- WmtRWTPSetDictIterator(const WmtRWTPSetDict<K, V>& c) :
- RWTValHashDictionaryIterator<K, WmtRWTPtrSet<V>* >(
- (RWTValHashDictionary<K, WmtRWTPtrSet<V>* >&)c) {}
-
- K key() const
- {
- return (K)RWTValHashDictionaryIterator<K, WmtRWTPtrSet<V>* >::key();
- }
- WmtRWTPtrSet<V> *value() const
- {
- return (WmtRWTPtrSet<V> *)
- RWTValHashDictionaryIterator<K, WmtRWTPtrSet<V>* >::value();
- }
- RWBoolean operator++()
- {
- return RWTValHashDictionaryIterator<K, WmtRWTPtrSet<V>* >::
- operator++();
- }
- void reset()
- {
- RWTValHashDictionaryIterator<K, WmtRWTPtrSet<V>* >::reset();
- }
- };
-
- #endif /* WMTRWTPSETDICT_HXX */
-