home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / NmFuncMap.hxx < prev    next >
Text File  |  1996-05-31  |  1KB  |  56 lines

  1. /*---------------------------------------------------------------------------
  2.  *
  3.  *      (c)     Westmount Technology    1993
  4.  *
  5.  *      File:        @(#)NmFuncMap.hxx    1.1
  6.  *      Author:        frmo, peku
  7.  *      Description:    A mapping from a name to a pointer to function
  8.  *            uses RogueWave RWCString and RWTValHashDictionary
  9.  *---------------------------------------------------------------------------
  10.  SccsId = @(#)NmFuncMap.hxx    1.1 21 Feb 1994 Copyright 1994 Westmount Technology */
  11.  
  12. #ifndef NMFUNCMAP_HXX
  13. #define NMFUNCMAP_HXX
  14.  
  15. #ifndef __RWCSTRING_H__
  16. #include "rw/cstring.h"
  17. #endif
  18.  
  19. #ifndef __RWTVHDICT_H__
  20. #include "rw/tvhdict.h"
  21. #endif
  22.  
  23. typedef void* voidptr;
  24.  
  25. unsigned WmtRWTHashRWCString(const RWCString& s);
  26.  
  27. template<class T>
  28. class NmFuncMap : private RWTValHashDictionary<RWCString, voidptr> {
  29. public:
  30.     NmFuncMap() :
  31.         RWTValHashDictionary<RWCString, voidptr>(WmtRWTHashRWCString)
  32.     {
  33.     }
  34.     void set(const RWCString &key, T func)
  35.     {
  36.         RWTValHashDictionary<RWCString, voidptr>::
  37.             insertKeyAndValue(*new RWCString(key), func);
  38.     }
  39.     T get(const RWCString &key) const
  40.     {
  41.         voidptr val;
  42.         RWTValHashDictionary<RWCString, voidptr>::findValue(key, val);
  43.         return (T) val;
  44.     }
  45.     void remove(const RWCString &key)
  46.     {
  47.         RWTValHashDictionary<RWCString, voidptr>::remove(key);
  48.     }
  49.     int isPresent(const RWCString &key) const
  50.     {
  51.         return RWTValHashDictionary<RWCString, voidptr>::contains(key);
  52.     }
  53. };
  54.  
  55. #endif /* NMFUNCMAP_HXX */
  56.