Leaked source code of windows server 2003
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.

226 lines
4.5 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. resdict.cxx
  5. Abstract:
  6. resource dictionary class implementations, if needed.
  7. Notes:
  8. History:
  9. VibhasC Aug-08-1993 Created.
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "becls.hxx"
  15. #pragma hdrstop
  16. short
  17. RESOURCE_DICT::GetListOfResources(
  18. ITERATOR& ListIter )
  19. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  20. Routine Description:
  21. Get a list of resources into the specified iterator.
  22. Arguments:
  23. ListIter - A reference to the iterator class where the list is
  24. accumulated.
  25. Return Value:
  26. A count of the number of resources.
  27. Notes:
  28. ----------------------------------------------------------------------------*/
  29. {
  30. RESOURCE * pR;
  31. Dict_Status Status;
  32. short Count = 0;
  33. //
  34. // Get to the top of the dictionary.
  35. //
  36. Status = Dict_Next( (pUserType) 0 );
  37. //
  38. // Iterate till the entire dictionary is done.
  39. //
  40. while( SUCCESS == Status )
  41. {
  42. pR = (RESOURCE *)Dict_Curr_Item();
  43. ITERATOR_INSERT( ListIter, pR );
  44. Count++;
  45. Status = Dict_Next( pR );
  46. }
  47. return Count;
  48. }
  49. void
  50. RESOURCE_DICT::Clear()
  51. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  52. Routine Description:
  53. Clear the dictionary of all resources allocated.
  54. Arguments:
  55. None.
  56. Return Value:
  57. None.
  58. Notes:
  59. ----------------------------------------------------------------------------*/
  60. {
  61. Dict_Status Status;
  62. RESOURCE * pResource;
  63. //
  64. // The way to delete all elements is to get to the top and then
  65. // do a get next, delete each one.
  66. //
  67. //
  68. // Note: Dict_Next() has a default parameter of null. This returns the
  69. // first record in the dictionary.
  70. //
  71. Status = Dict_Next();
  72. while( SUCCESS == Status )
  73. {
  74. pResource = (RESOURCE *)Dict_Curr_Item();
  75. Status = Dict_Delete( (pUserType *) &pResource );
  76. delete pResource;
  77. }
  78. }
  79. RESOURCE *
  80. RESOURCE_DICT::Insert(
  81. PNAME pResourceName,
  82. node_skl * pType )
  83. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84. Routine Description:
  85. Insert a resource in the dictionary.
  86. Arguments:
  87. pName - Name of the resource being inserted.
  88. Return Value:
  89. The resource which was created and inserted.
  90. Notes:
  91. Search for the resource, if it already exists, dont insert. This
  92. may really be an overkill for the code generator, since the code
  93. generator usually knows when to insert a resource. If necessary
  94. we can remove this.
  95. ----------------------------------------------------------------------------*/
  96. {
  97. RESOURCE * pResource;
  98. RESOURCE DummyResource( pResourceName, (node_skl *)0 );
  99. Dict_Status Status = Dict_Find( &DummyResource );
  100. switch( Status )
  101. {
  102. case EMPTY_DICTIONARY:
  103. case ITEM_NOT_FOUND:
  104. pResource = new RESOURCE( pResourceName, pType );
  105. Dict_Insert( (pUserType) pResource );
  106. return pResource;
  107. default:
  108. return (RESOURCE *)Dict_Curr_Item();
  109. }
  110. }
  111. RESOURCE *
  112. RESOURCE_DICT::Search(
  113. PNAME pResourceName )
  114. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  115. Routine Description:
  116. Search for a resource in the dictionary.
  117. Arguments:
  118. pResourceName - Name of the resource being searched for.
  119. Return Value:
  120. A pointer to the resource expression if found.
  121. NULL otherwise.
  122. Notes:
  123. ----------------------------------------------------------------------------*/
  124. {
  125. //
  126. // In order to search, we must create a dummy resource to compare
  127. // against.
  128. //
  129. RESOURCE DummyResource( pResourceName, (node_skl *)0 );
  130. Dict_Status Status;
  131. //
  132. // Search.
  133. //
  134. Status = Dict_Find( &DummyResource );
  135. switch( Status )
  136. {
  137. case EMPTY_DICTIONARY:
  138. case ITEM_NOT_FOUND:
  139. return (RESOURCE *)0;
  140. default:
  141. return (RESOURCE *)Dict_Curr_Item();
  142. }
  143. }
  144. SSIZE_T
  145. RESOURCE_DICT::Compare(
  146. void * p1,
  147. void * p2 )
  148. {
  149. RESOURCE * pRes1 = (RESOURCE *)p1;
  150. RESOURCE * pRes2 = (RESOURCE *)p2;
  151. p1 = pRes1->GetResourceName();
  152. p2 = pRes2->GetResourceName();
  153. return strcmp((const char *)p1, (const char *)p2);
  154. }
  155. void
  156. PrintResourceKey( void * p )
  157. {
  158. ((void)(p));
  159. }