home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / AEHSHTBL.H < prev    next >
Text File  |  1997-02-28  |  6KB  |  205 lines

  1. /* @(#)Z 1.3 os2/src/storage/aehshtbl.h, oddataxfer, od96os2, odos29646d 96/11/15 15:50:01 (96/08/23 01:42:58) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: oddataxfer
  6.  *
  7.  *   CLASSES:   AEHashTable
  8.  *        AEHashTableIterator
  9.  *
  10.  *   ORIGINS: 82,27
  11.  *
  12.  *
  13.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  14.  *   All Rights Reserved
  15.  *   Licensed Materials - Property of IBM
  16.  *   US Government Users Restricted Rights - Use, duplication or
  17.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18.  *       
  19.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  23.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  24.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25.  *   OR PERFORMANCE OF THIS SOFTWARE.
  26.  */
  27. /*====END_GENERATED_PROLOG========================================
  28.  */
  29.  
  30. /********************************************************************/
  31. /*                                                                  */
  32. /* Copyright (C) Apple Computer, Inc., 1994                         */
  33. /*                                                                  */
  34. /********************************************************************/
  35.  
  36. /*
  37.   File:    AEHshTbl.h
  38.  
  39.   Contains:  Interface to AppleEvent hash table code and XMPAEHashTable
  40.         class.
  41.  
  42.   Owned by:  Nick Pilch
  43.  
  44.   Copyright:  ⌐ 1993-94 by Apple Computer, Inc., all rights reserved.
  45.  
  46. */
  47.  
  48. #ifndef _AEHSHTBL_
  49. #define _AEHSHTBL_
  50.  
  51. #ifndef _ODTYPES_
  52. #include "ODTypes.h"
  53. #endif
  54.  
  55. #ifndef _PLFMDEF_
  56. #include "PlfmDef.h"
  57. #endif
  58.  
  59. #ifdef _PLATFORM_OS2_
  60. #include <odtypesp.h>
  61. #endif
  62.  
  63. //==============================================================================
  64. // Theory of Operation
  65. //==============================================================================
  66.  
  67. /*
  68.   C Interface to some of the routines in HashTabl.A and class wrapper.
  69.  
  70.   The class simply provides an object-oriented wrapper to the AE hash table
  71.   functions found in HashTable.A. It removes access to the MemHooks parameter. (MemHooks is set to NULL and SysHeap is set to false.)
  72.   It hides the Table parameter since that is a member variable of the class.
  73. */
  74.  
  75. //==============================================================================
  76. // Scalar Types
  77. //==============================================================================
  78.  
  79. typedef void* ODEntryPtr;
  80. typedef void* ODKeyPtr;
  81.  
  82. #ifndef _PLATFORM_OS2_
  83. typedef  Handle HashTable;
  84. #else
  85. class    HCollection;
  86. typedef  HCollection *HashTable;
  87. class    HCollectionCursor;
  88. typedef  HCollectionCursor *HashTableCursor;
  89. #endif // ! _PLATFORM_OS2_
  90.  
  91. //==============================================================================
  92. // Error Codes
  93. //==============================================================================
  94.  
  95. const ODSShort kAEErrAlreadyExists  = -1722;
  96. const ODSShort kAEErrNotFound    = -1723;
  97. const ODSShort kAEErrEndOfTable  = -1724;
  98.  
  99.  
  100. //==============================================================================
  101. // Classes defined in this interface
  102. //==============================================================================
  103.  
  104. #ifdef _PLATFORM_OS2_
  105. class    HCollection;
  106. typedef  HCollection *HashTable;
  107. class    HCollectionCursor;
  108. typedef  HCollectionCursor *HashTableCursor;
  109. #endif
  110.  
  111. class AEHashTable;
  112. class AEHashTableIterator;
  113.  
  114. //==============================================================================
  115. // AEHashTable
  116. //==============================================================================
  117.  
  118. class AEHashTable
  119. {  
  120. #ifndef _PLATFORM_OS2_
  121.   friend class AEHashTableIterator;
  122. #endif
  123.  
  124.   public:
  125.  
  126.   AEHashTable();
  127.   ODVMethod void Initialize(ODULong numEntries, ODUShort keySize,
  128.                 ODUShort valueSize, ODBoolean inSysHeap);
  129.     // kODErrOutOfMemory is thrown if the table cannot be created.
  130.  
  131.   virtual ~AEHashTable();
  132.  
  133.   ODVMethod void      ReplaceEntry(ODKeyPtr key, ODEntryPtr value);
  134.     // Replace and/or add an entry. Pass a POINTER to the key as well as a
  135.     //  a POINTER to the value to be added. kODErrOutOfMemory is thrown if
  136.     //  the entry cannot be added.
  137.  
  138.   ODVMethod void      RemoveEntry(ODKeyPtr key);
  139.     // Pass a POINTER to the key.
  140.  
  141.   ODVMethod ODBoolean  GetValue(ODKeyPtr key, ODEntryPtr value);
  142.     // Pass a POINTER to the key as well as a POINTER to the value to be
  143.     //  retrieved. kODTrue is returned if the key was found, kODFalse
  144.     //  otherwise.
  145.     
  146.   ODVMethod ODBoolean  Exists(ODKeyPtr key);
  147.     // Check to see if a key exists. This function is no faster than
  148.     //  GetValue and should probably only be used when you do not intend to
  149.     //  fetch the value immediately. kODTrue is returned if the key exists,
  150.     //  kODFalse, otherwise.
  151.   
  152. #ifndef _PLATFORM_OS2_
  153.   protected:
  154. #else
  155.   private:
  156. #endif
  157.  
  158.   HashTable  fAEHashTable;
  159.   ODUShort   fValueSize;
  160.   
  161. #ifdef _PLATFORM_OS2_
  162.   int        fKeySize, fEntrySize;
  163.   friend class AEHashTableIterator;
  164. #endif
  165.  
  166.   HashTable  GetAEHashTable();
  167. };
  168.  
  169. //==============================================================================
  170. // AEHashTableIterator
  171. //
  172. //  This iterator is only meant to be used in the the context of a for loop,
  173. //  e.g.:
  174. //
  175. //  AEHashTableIterator iter;
  176. //  for (iter.First(key, value); iter.IsNotComplete(); iter.Next(key, value))
  177. //  {
  178. //    ...
  179. //  }
  180. //
  181. //==============================================================================
  182.  
  183. class AEHashTableIterator
  184. {
  185.   public:
  186.   AEHashTableIterator(AEHashTable* table);
  187.   ~AEHashTableIterator();
  188.   
  189.   void      First(ODKeyPtr key, ODEntryPtr value);
  190.   void      Next(ODKeyPtr key, ODEntryPtr value);
  191.   ODBoolean    IsNotComplete();
  192.   private:
  193. #ifndef _PLATFORM_OS2_
  194.   AEHashTable* fTable;
  195.   ODSLong    fIndex;
  196.   ODBoolean    fDone;
  197.   ODBoolean    GetNext(ODKeyPtr key, ODEntryPtr value);
  198. #else
  199.   HashTable       fTable;
  200.   HashTableCursor cursor;
  201. #endif // ! _PLATFORM_OS2_
  202. };
  203.  
  204. #endif // _AEHSHTBL_
  205.