Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1990 - 1999
  6. //
  7. // File: sdict.hxx
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. File : sdict.hxx
  12. Title : A simple dictionary.
  13. Description :
  14. History :
  15. -------------------------------------------------------------------- */
  16. #ifndef __SDICT_HXX__
  17. #define __SDICT_HXX__
  18. typedef int DictionaryCursor;
  19. #define INITIALDICTSLOTS 4
  20. class SIMPLE_DICT
  21. {
  22. protected:
  23. void * * DictSlots;
  24. int cDictSlots;
  25. int cDictSize;
  26. void * InitialDictSlots[INITIALDICTSLOTS];
  27. public:
  28. SIMPLE_DICT ( // Constructor.
  29. );
  30. ~SIMPLE_DICT ( // Destructor.
  31. );
  32. int // Return the key in the dictionary for the item just inserted.
  33. Insert ( // Insert an item in the dictionary and return its key.
  34. void *Item // The item to insert.
  35. );
  36. void * // Returns the item if found, and 0 otherwise.
  37. Find ( // Find an item in the dictionary.
  38. int Key // The key of the item.
  39. );
  40. void * // Returns the item being deleted.
  41. Delete ( // Delete an item from the dictionary.
  42. int Key // The key of the item being deleted.
  43. );
  44. int // Returns the number of items in the dictionary.
  45. Size ( // Returns the number of items in the dictionary.
  46. ) {return(cDictSize);}
  47. // expands the capacity of the dictionary to the given size.
  48. // Will return non-zero if successful, or 0 otherwise.
  49. int
  50. ExpandToSize (
  51. int Size
  52. );
  53. void
  54. DeleteAll (
  55. void
  56. );
  57. void
  58. Reset (DictionaryCursor &cursor // Resets the dictionary, so that when Next is called,
  59. // the first item will be returned.
  60. ) {cursor = 0;}
  61. void * // Returns the next item or 0 if at the end.
  62. Next (DictionaryCursor &cursor);
  63. void *
  64. DeleteItemByBruteForce(
  65. void * Item
  66. );
  67. void *RemoveNext (DictionaryCursor &cursor);
  68. void *NextWithKey (DictionaryCursor &cursor, int *Key);
  69. };
  70. #define NEW_BASED_SDICT(TYPE, BASE) \
  71. \
  72. class TYPE; \
  73. \
  74. class TYPE##_DICT : public BASE \
  75. { \
  76. public: \
  77. \
  78. TYPE##_DICT () {} \
  79. ~TYPE##_DICT () {} \
  80. \
  81. TYPE * \
  82. Find (int Key) \
  83. {return((TYPE *) BASE##::Find(Key));} \
  84. \
  85. TYPE * \
  86. Delete (int Key) \
  87. {return((TYPE *) BASE##::Delete(Key));} \
  88. \
  89. TYPE * \
  90. Next (DictionaryCursor &cursor) \
  91. {return((TYPE *) BASE##::Next(cursor));} \
  92. TYPE * \
  93. RemoveNext (DictionaryCursor &cursor) \
  94. {return((TYPE *) BASE##::RemoveNext(cursor));} \
  95. TYPE * \
  96. NextWithKey (DictionaryCursor &cursor, int *Key) \
  97. {return((TYPE *) BASE##::NextWithKey(cursor, Key));} \
  98. }
  99. #define NEW_SDICT(TYPE) NEW_BASED_SDICT(TYPE, SIMPLE_DICT)
  100. #define NEW_SHARED_DICT(TYPE) NEW_BASED_SDICT(TYPE, SHARED_DICT)
  101. inline void *
  102. SIMPLE_DICT::Find (
  103. int Key
  104. )
  105. {
  106. if (Key >= cDictSlots)
  107. return(Nil);
  108. return(DictSlots[Key]);
  109. }
  110. #endif // __SDICT_HXX__