home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / WmtRWTOPSetDict.hxx < prev    next >
Text File  |  1997-11-12  |  3KB  |  96 lines

  1. /*---------------------------------------------------------------------------
  2.  *
  3.  *      (c)     Westmount Technology    1994
  4.  *
  5.  *      File:        @(#)WmtRWTOPSetDict.hxx    /main/titanic/1
  6.  *      Author:        wmt
  7.  *      Description:    ordered pointer set dictionary based on RogueWave
  8.  *            library
  9.  *---------------------------------------------------------------------------
  10.  SccsId = @(#)WmtRWTOPSetDict.hxx    /main/titanic/1   2/21/94 Copyright 1994 Westmount Technology */
  11.  
  12. #ifndef WMTRWTOPSETDICT_HXX
  13. #define WMTRWTOPSETDICT_HXX
  14.  
  15. #ifndef __RWTVHDICT_H__
  16. #include "rw/tvhdict.h"
  17. #endif
  18.  
  19. #ifndef WMTRWTOPTRSET_HXX
  20. #include "WmtRWTOPtrSet.hxx"
  21. #endif
  22.  
  23. template<class K, class V>
  24. class WmtRWTOPSetDict : private RWTValHashDictionary<K, WmtRWTOPtrSet<V>* > {
  25. public:
  26.     WmtRWTOPSetDict(unsigned (*hashKey)(const K&)) :
  27.         RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >(hashKey)
  28.     {
  29.     }
  30.     RWBoolean doFindValue(const K& key, WmtRWTOPtrSet<V>* &retval) const
  31.     {
  32.       if (! RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >::findValue(
  33.                           key, retval)) {
  34.           return FALSE;
  35.       } else {
  36.           return TRUE;
  37.       }
  38.     }
  39.     void doInsertKeyAndValue(const K& key, V *val)
  40.     {
  41.       if (! RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >::contains(key)) {
  42.         RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >::insertKeyAndValue(
  43.                        key, new WmtRWTOPtrSet<V>);
  44.       }
  45.       WmtRWTOPtrSet<V> *set;
  46.       RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >::findValue(key, set);
  47.       set->append(val);
  48.     }
  49.     RWBoolean doRemoveKeyAndValue(const K& key, V *val)
  50.     { 
  51.       WmtRWTOPtrSet<V> *set;
  52.       if (doFindValue(key, set)) {
  53.         set->remove(val);
  54.         if (set->isEmpty()) {
  55.         RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >::remove(key);
  56.             delete set;
  57.         }
  58.         return TRUE;
  59.       } else {
  60.         return FALSE;
  61.       }
  62.     }
  63.     //void doClear()
  64.     //    { RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >::clear(); }
  65. };
  66.  
  67. template <class K, class V>
  68. class WmtRWTOPSetDictIterator :
  69.     private RWTValHashDictionaryIterator<K, WmtRWTOPtrSet<V>* > {
  70. public:
  71.     WmtRWTOPSetDictIterator(const WmtRWTOPSetDict<K, V>& c) :
  72.         RWTValHashDictionaryIterator<K, WmtRWTOPtrSet<V>* >(
  73.         (RWTValHashDictionary<K, WmtRWTOPtrSet<V>* >&)c) {}
  74.  
  75.     K key() const
  76.     {
  77.       return (K)RWTValHashDictionaryIterator<K, WmtRWTOPtrSet<V>* >::key();
  78.     }
  79.     WmtRWTOPtrSet<V> *value() const
  80.     {
  81.       return (WmtRWTOPtrSet<V> *)
  82.           RWTValHashDictionaryIterator<K, WmtRWTOPtrSet<V>* >::value();
  83.     }
  84.     RWBoolean operator++()
  85.     {
  86.       return RWTValHashDictionaryIterator<K, WmtRWTOPtrSet<V>* >::
  87.           operator++();
  88.     }
  89.     void reset()
  90.     {
  91.       RWTValHashDictionaryIterator<K, WmtRWTOPtrSet<V>* >::reset();
  92.     }
  93. };
  94.  
  95. #endif /* WMTRWTOPSETDICT_HXX */
  96.