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.

265 lines
5.4 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. pdict.cxx
  5. Abstract:
  6. This file stores the indexes of all class assocation entries based on IID.
  7. Notes:
  8. History:
  9. VibhasC Sep-29-1996 Created.
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "precomp.hxx"
  15. void
  16. PDICT::Clear()
  17. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. Routine Description:
  19. Clear the dictionary of all ITF_ENTRY indexes allocated.
  20. NOTE: tHIS FUNCTION DOES NOT DELETE THE ITF_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. PACKAGE_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 = (PACKAGE_ENTRY *)Dict_Curr_Item();
  43. Status = Dict_Delete( (pUserType *) &pClassEntry );
  44. }
  45. }
  46. PACKAGE_ENTRY *
  47. PDICT::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. PACKAGE_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 = (PACKAGE_ENTRY *)Dict_Curr_Item();
  67. else
  68. return 0;
  69. }
  70. PACKAGE_ENTRY *
  71. PDICT::GetNext( PACKAGE_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 = (PACKAGE_ENTRY *)Dict_Curr_Item();
  94. else
  95. return 0;
  96. }
  97. PACKAGE_ENTRY *
  98. PDICT::Insert(
  99. PACKAGE_ENTRY * pClassEntry )
  100. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  101. Routine Description:
  102. Insert a class entry in the index.
  103. Arguments:
  104. Return Value:
  105. A pointer to the PACKAGE_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 (PACKAGE_ENTRY *)Dict_Curr_Item();
  120. }
  121. }
  122. PACKAGE_ENTRY *
  123. PDICT::Search(
  124. char * Name, DWORD Context )
  125. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  126. Routine Description:
  127. Search for a class entry in the dictionary.
  128. Arguments:
  129. pClassEntry - Name of the PACKAGE_ENTRY being searched for.
  130. Return Value:
  131. A pointer to the PACKAGE_ENTRY expression if found.
  132. NULL otherwise.
  133. Notes:
  134. ----------------------------------------------------------------------------*/
  135. {
  136. //
  137. // In order to search, we must create a dummy PACKAGE_ENTRY to compare
  138. // against. We initialize this with the class id passed and search for it.
  139. //
  140. PACKAGE_ENTRY DummyPackageEntry;
  141. Dict_Status Status;
  142. memset(&DummyPackageEntry, '\0', sizeof( PACKAGE_ENTRY ) );
  143. strcpy( (char *)&DummyPackageEntry.PackageName, Name );
  144. DummyPackageEntry.PackageDetails.dwContext = Context;
  145. //
  146. // Search.
  147. //
  148. Status = Dict_Find( &DummyPackageEntry );
  149. switch( Status )
  150. {
  151. case EMPTY_DICTIONARY:
  152. case ITEM_NOT_FOUND:
  153. return (PACKAGE_ENTRY *)0;
  154. default:
  155. return (PACKAGE_ENTRY *)Dict_Curr_Item();
  156. }
  157. }
  158. int
  159. PDICT::Compare(
  160. void * p1,
  161. void * p2 )
  162. {
  163. PACKAGE_ENTRY * pRes1 = (PACKAGE_ENTRY *)p1;
  164. PACKAGE_ENTRY * pRes2 = (PACKAGE_ENTRY *)p2;
  165. char * pName1 = &pRes1->PackageName[0];
  166. char * pName2 = &pRes2->PackageName[0];
  167. int Result;
  168. Result = _stricmp( pName1, pName2 );
  169. Result = (Result < 0) ? -1 : (Result > 0) ? 1 : 0;
  170. #if 0
  171. if( Result == 0 )
  172. {
  173. Result = (long)( pRes1->PackageDetails.dwContext ) - (long)(pRes2->PackageDetails.dwContext);
  174. Result = (Result < 0) ? -1 : (Result > 0) ? 1 : 0;
  175. }
  176. #endif // 0
  177. return Result;
  178. }
  179. void
  180. PrintPACKAGE_ENTRYKey( void * p )
  181. {
  182. ((void)(p));
  183. }