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.

248 lines
4.9 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. clsdict.cxx
  5. Abstract:
  6. This file stores the indexes of all class assocation entries based on clsid.
  7. Notes:
  8. History:
  9. VibhasC Sep-29-1996 Created.
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "precomp.hxx"
  15. void
  16. CLSDICT::Clear()
  17. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. Routine Description:
  19. Clear the dictionary of all CLASS_ENTRY indexes allocated.
  20. NOTE: tHIS FUNCTION DOES NOT DELETE THE CLASS_ENTRY, BUT ONLY THE INDEX
  21. OF THE CLASS ENTRY
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. Notes:
  27. ----------------------------------------------------------------------------*/
  28. {
  29. Dict_Status Status;
  30. CLASS_ENTRY * pClassEntry;
  31. //
  32. // The way to delete all elements is to get to the top and then
  33. // do a get next, delete each one.
  34. //
  35. //
  36. // Note: Dict_Next() has a default parameter of null. This returns the
  37. // first record in the dictionary.
  38. //
  39. Status = Dict_Next();
  40. while( SUCCESS == Status )
  41. {
  42. pClassEntry = (CLASS_ENTRY *)Dict_Curr_Item();
  43. Status = Dict_Delete( (pUserType *) &pClassEntry );
  44. }
  45. }
  46. CLASS_ENTRY *
  47. CLSDICT::GetFirst()
  48. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  49. Routine Description:
  50. Get the first item in the dictionary
  51. Arguments:
  52. None.
  53. Return Value:
  54. None.
  55. Notes:
  56. ----------------------------------------------------------------------------*/
  57. {
  58. Dict_Status Status;
  59. CLASS_ENTRY * pClassEntry;
  60. //
  61. // Dict_Next() has a default parameter of null. This returns the
  62. // first record in the dictionary.
  63. //
  64. Status = Dict_Next();
  65. if( SUCCESS == Status )
  66. return pClassEntry = (CLASS_ENTRY *)Dict_Curr_Item();
  67. else
  68. return 0;
  69. }
  70. CLASS_ENTRY *
  71. CLSDICT::GetNext( CLASS_ENTRY * pLastClassEntry)
  72. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  73. Routine Description:
  74. Get the next item in the dictionary
  75. Arguments:
  76. pLastClassEntry.
  77. Return Value:
  78. None.
  79. Notes:
  80. pLastClassEntry is the entry returned by the previous call to GetFirst
  81. or GetNext. This is the seed for this search.
  82. This function returns a zero if there are no more entries in the
  83. dictionary.
  84. ----------------------------------------------------------------------------*/
  85. {
  86. Dict_Status Status;
  87. //
  88. // Dict_Next() has a default parameter of null. This returns the
  89. // first record in the dictionary. But if we supply the last searched
  90. // item, we get the next in the dictionary.
  91. //
  92. if( (Status = Dict_Next( pLastClassEntry) ) == SUCCESS )
  93. return pLastClassEntry = (CLASS_ENTRY *)Dict_Curr_Item();
  94. else
  95. return 0;
  96. }
  97. CLASS_ENTRY *
  98. CLSDICT::Insert(
  99. CLASS_ENTRY * pClassEntry )
  100. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  101. Routine Description:
  102. Insert a class entry in the index.
  103. Arguments:
  104. Return Value:
  105. A pointer to the CLASS_ENTRY entry which was created and inserted.
  106. Notes:
  107. Search for the class association entry and if it exists, return that,
  108. do not create a new one.
  109. ----------------------------------------------------------------------------*/
  110. {
  111. Dict_Status Status = Dict_Find( pClassEntry );
  112. switch( Status )
  113. {
  114. case EMPTY_DICTIONARY:
  115. case ITEM_NOT_FOUND:
  116. Dict_Insert( (pUserType) pClassEntry );
  117. return pClassEntry;
  118. default:
  119. return (CLASS_ENTRY *)Dict_Curr_Item();
  120. }
  121. }
  122. CLASS_ENTRY *
  123. CLSDICT::Search(
  124. char * Clsid )
  125. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  126. Routine Description:
  127. Search for a class entry in the dictionary.
  128. Arguments:
  129. pClassEntry - Name of the CLASS_ENTRY being searched for.
  130. Return Value:
  131. A pointer to the CLASS_ENTRY expression if found.
  132. NULL otherwise.
  133. Notes:
  134. ----------------------------------------------------------------------------*/
  135. {
  136. //
  137. // In order to search, we must create a dummy CLASS_ENTRY to compare
  138. // against. We initialize this with the class id passed and search for it.
  139. //
  140. CLASS_ENTRY DummyClassEntry;
  141. Dict_Status Status;
  142. memcpy( &DummyClassEntry, Clsid, SIZEOF_STRINGIZED_CLSID );
  143. //
  144. // Search.
  145. //
  146. Status = Dict_Find( &DummyClassEntry );
  147. switch( Status )
  148. {
  149. case EMPTY_DICTIONARY:
  150. case ITEM_NOT_FOUND:
  151. return (CLASS_ENTRY *)0;
  152. default:
  153. return (CLASS_ENTRY *)Dict_Curr_Item();
  154. }
  155. }
  156. int
  157. CLSDICT::Compare(
  158. void * p1,
  159. void * p2 )
  160. {
  161. CLASS_ENTRY * pRes1 = (CLASS_ENTRY *)p1;
  162. CLASS_ENTRY * pRes2 = (CLASS_ENTRY *)p2;
  163. return _memicmp( p1, p2, SIZEOF_STRINGIZED_CLSID );
  164. }
  165. void
  166. PrintCLASS_ENTRYKey( void * p )
  167. {
  168. ((void)(p));
  169. }