home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 November / VPR9611B.ISO / vabasic / ntclnt.exe / DISK8 / data.8 / datab / INCLUDE / VDIC.HH < prev    next >
Text File  |  1996-07-29  |  4KB  |  110 lines

  1. /*------------------------------------------------------------------------
  2.  * $Source: /rcs/crcs/general/vdic.hh,v $
  3.  * $Date: 1995/11/10 23:55:24 $                   $Revision: 1.17 $
  4.  *
  5.  * Copyright 1990, Visual Edge Software Ltd.
  6.  * -----------------------------------------
  7.  * ALL RIGHTS RESERVED.  This notice is intended as a precaution against
  8.  * inadvertent publication, and shall not be deemed to constitute an 
  9.  * acknowledgment that publication has  occurred nor to imply any waiver  
  10.  * of confidentiality.  The year included in the notice is the year 
  11.  * of the creation of the work.                    
  12.  *------------------------------------------------------------------------
  13.  * Class VeDictionary
  14.  * -----------------
  15.  * A dictionary is a space-managing hash table associating string keys
  16.  * with entries over any pointer type.
  17.  * Dictionaries are -shared- by assignment, value parameter passing, etc,
  18.  * just like VArrays.
  19.  *
  20.  * This template class, based on VePDictionary, uses only a few inlines
  21.  * to wrap VePDictionary for typed use. 
  22.  *---------------------------------------------------------------------------*/
  23.  
  24. #ifndef VDICO_HH
  25. #define VDICO_HH
  26.  
  27. #include <os.h>        // For NOTEMPLATES
  28.  
  29. #ifndef NOTEMPLATES
  30.  
  31. #include <visedge.hh>
  32. #include <vstring.hh>
  33. #include <ptrdic.hh>
  34.  
  35. #if     TP_TYPE_REPEAT
  36. #define VPD_TYPE        VeDictionary<Entry>
  37. #else
  38. #define VPD_TYPE        VeDictionary
  39. #endif  
  40.  
  41.  
  42. template<class Entry> class VeDictionary : public VePDictionary
  43. {
  44. public:
  45.  
  46.     VeDictionary() {}
  47.     VeDictionary (int hashsize) :  VePDictionary(hashsize) {}
  48.     VeDictionary (const VeDictionary<Entry> &other) : VePDictionary(other) {}
  49.     VeDictionary (const VePDictionary& other) : VePDictionary(other) {}
  50.     
  51.     operator=  (const VePDictionary &other)  
  52.         { this->VePDictionary::operator=(other); return *this;}
  53.  
  54.  
  55.     /*--------------------------------------------------
  56.      * Explicit insertion of entries.
  57.      *--------------------------------------------------*/
  58.  
  59.     Entry&  PutAt (const char* k, const Entry e)
  60.         {return (Entry&) VePDictionary::PutAt(k, (PVoid)e); }
  61.  
  62.     Entry&  PutAt (const VeString&  k, const Entry e)
  63.         {return (Entry&) VePDictionary::PutAt(k, (PVoid)e); }
  64.  
  65.     /*-------------------------------------------------- 
  66.      * Extraction of entries - adding unfound ones!
  67.      *--------------------------------------------------*/
  68.  
  69.     Entry& Get (const char* k)    
  70.         { return (Entry&) VePDictionary::Get(k); }
  71.  
  72.     Entry& Get (const VeString& k) 
  73.         { return (Entry&) VePDictionary::Get(k); }
  74.  
  75.     Entry FindElement (int &i, PVoid &aCell, VeString *aKey = 0) 
  76.         { return (Entry) VePDictionary::FindElement(i, aCell, aKey); }
  77.  
  78.     Entry& operator[] (const char* k)       { return Get(k); }
  79.     Entry& operator[] (const VeString& k)    { return Get(k); }
  80.  
  81.     /*-----------------------------------------------------
  82.      * Find out if a given key has an entry.
  83.      *-----------------------------------------------------*/
  84.     inline bool_t Query (const char* k, Entry& res)    
  85.     {
  86.         PVoid result;
  87.         bool_t found = VePDictionary::Query(k, result);
  88.         res = (Entry) result;
  89.         return found;
  90.     }
  91.  
  92.     inline bool_t Query (const VeString& k, Entry& res)    
  93.     {
  94.         PVoid result;
  95.         bool_t found = VePDictionary::Query(k, result);
  96.         res = (Entry) result;
  97.         return found;
  98.     }
  99.  
  100.     /*-------------------------------------------------- 
  101.      * Shrinking.  Remove() returns the removed element.
  102.      *--------------------------------------------------*/
  103.  
  104.     Entry Remove(const char* k)
  105.         { return (Entry) VePDictionary::Remove(k); }
  106. };
  107. #endif // NOTEMPLATES
  108.  
  109. #endif
  110.