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

  1. /*------------------------------------------------------------------------
  2.  * $Source: /rcs/crcs/general/ptrdic.hh,v $
  3.  * $Date: 1995/11/10 23:55:40 $                   $Revision: 1.11 $
  4.  *
  5.  * Copyright 1993, 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 VePDictionary
  14.  * -----------------
  15.  * A dictionary is a space-managing hash table associating string keys
  16.  * with pointer entries.
  17.  *
  18.  * VDictionaries are -shared- by assignment, value parameter passing, etc,
  19.  * just like VArrays.
  20.  *---------------------------------------------------------------------------*/
  21.  
  22. #ifndef VPTRDIC_HH
  23. #define VPTRDIC_HH
  24.  
  25. #include <visedge.hh>
  26. #include <dllclass.hh>
  27. #include <vstring.hh>
  28.  
  29. class VPDicoCell;
  30.  
  31. #ifdef NOTEMPLATES
  32. #include <mst/dicelary.mst>
  33. #else
  34. #include <varray.hh>
  35. typedef VeArray<VPDicoCell *> VePDicoCellArray;
  36. #endif
  37.  
  38. class VePDictionary : public VeDllBasedClass
  39. {
  40. public:
  41.  
  42.     VOPERDECL          VePDictionary ();
  43.     VOPERDECL          VePDictionary (int hashsize);
  44.     VOPERDECL          VePDictionary (const VePDictionary&);
  45.     virtual VOPERDECL    ~VePDictionary();
  46.  
  47.     VMETHODDECL(VePDictionary&)    operator=(const VePDictionary&);
  48.  
  49.     VOPERDECL          operator int();         // return hash size
  50.  
  51.     /*--------------------------------------------------
  52.      * Explicit insertion of entries.
  53.      *--------------------------------------------------*/
  54.  
  55.     VMETHODDECL(PVoid&)     PutAt (const char*, const PVoid);
  56.     VMETHODDECL(PVoid&)     PutAt (const VeString&, const PVoid);
  57.  
  58.     /*-------------------------------------------------- 
  59.      * Extraction of entries - adding unfound ones!
  60.      *--------------------------------------------------*/
  61.  
  62.     VMETHODDECL(PVoid&)    operator[] (const char*);
  63.     VMETHODDECL(PVoid&)    operator[] (const VeString& );
  64.     VMETHODDECL(PVoid&)    Get (const char*);
  65.     VMETHODDECL(PVoid&)    Get (const VeString&);
  66.  
  67.     VMETHODDECL(bool_t)    Query (const char*, PVoid& entry);
  68.     VMETHODDECL(bool_t)    Query (const VeString&, PVoid& entry);
  69.     VMETHODDECL(PVoid)     FindElement(int &i, PVoid &cell,
  70.                             VeString *aKey = 0);
  71.  
  72.     /*-------------------------------------------------- 
  73.      * Shrinking.  Remove() returns the removed element.
  74.      *--------------------------------------------------*/
  75.  
  76.     VMETHODDECL(PVoid)    Remove (const char* key);
  77.     VMETHODDECL(void)       RemoveAll ();
  78.  
  79.     /*--------------------------------------------------
  80.      * Iteration over a dictionary is done using keys.
  81.      *--------------------------------------------------*/
  82.     VMETHODDECL(const char*)    FirstKey();
  83.     VMETHODDECL(const char*)    NextKey(const char*);
  84.  
  85.     /*-------------------------------------------------- 
  86.      * Find an element (== PVoid, or supplied predicate) 
  87.      *--------------------------------------------------*/
  88.  
  89.     VMETHODDECL(const char*)    KeyOf (const PVoid e) ;     
  90.  
  91.     VMETHODDECL(bool_t)          HasKey (const char* key) ;
  92.     
  93.     /*-------------------------------------------------- 
  94.      * Copying.  These make unshared duplicates.
  95.      *--------------------------------------------------*/
  96.  
  97.     VMETHODDECL(VePDictionary)    Duplicate () ;    
  98.     VMETHODDECL(void)             BecomeLike (VePDictionary&); 
  99.  
  100. private:
  101.  
  102.     VPDicoCell* FindCell(const char*, int& index);
  103.  
  104.     /*-----------------------------------------------------
  105.      * INVARIANT (itsTable.Length() == itsHashSize)
  106.      *-----------------------------------------------------*/
  107.  
  108.     VePDicoCellArray itsTable;
  109.  
  110.     int     itsHashSize;
  111. };
  112.  
  113.  
  114.  
  115. #endif // VPTRDIC_HH
  116.