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.

151 lines
4.4 KiB

  1. /*
  2. * viewlist.cxx
  3. *
  4. *
  5. * Copyright (c) 1998 Microsoft Corporation
  6. *
  7. * PURPOSE: Implements the CGenericSnapin class.
  8. *
  9. *
  10. * OWNER: vivekj
  11. */
  12. #include <headers.hxx>
  13. //---------------------------------------------------------------------------------
  14. // class CViewItemList
  15. /* CViewItemList::CViewItemList
  16. *
  17. * PURPOSE: Constructor
  18. *
  19. * PARAMETERS: None
  20. */
  21. CViewItemList::CViewItemList()
  22. {
  23. m_pitemSelectedContainer= NULL;
  24. m_fValid = FALSE;
  25. m_datSort = datNil;
  26. }
  27. /* CViewItemList::Initialize
  28. *
  29. * PURPOSE: Initializes a view, by creating pointers to all items underneath the selected container, and
  30. * sorting them.
  31. *
  32. * PARAMETERS:
  33. * CBaseSnapinItem * pitemSelectedContainer: The container containing the items we need to enumerate.
  34. * DAT datPresort: The dat according to which the list of items is already sorted.
  35. * DAT datSort: The dat according to which the view is sorted.
  36. *
  37. * RETURNS:
  38. * void
  39. */
  40. void
  41. CViewItemList::Initialize(CBaseSnapinItem *pitemSelectedContainer, DAT datPresort, DAT datSort)
  42. {
  43. CBaseSnapinItem * pitem = NULL;
  44. Invalidate(); // delete any existing items and clear the valid flag
  45. pitem = pitemSelectedContainer->PitemChild(); // get the first child item
  46. while (pitem) // Iterate through all the children
  47. {
  48. push_back(pitem); // Insert each item
  49. pitem = pitem->PitemNext();
  50. }
  51. if (datPresort != datSort) // need to sort if not already in the correct order.
  52. Sort();
  53. SaveSortResults(); // need to save the results for fast lookup.
  54. m_fValid = TRUE; // set the valid flag
  55. return;
  56. }
  57. /* CViewItemList::Sort
  58. *
  59. * PURPOSE: Sorts the view list according to DatSort().
  60. *
  61. * PARAMETERS: None
  62. *
  63. * RETURNS:
  64. * void
  65. */
  66. void
  67. CViewItemList::Sort()
  68. {
  69. }
  70. /* CViewItemList::SaveSortResults
  71. *
  72. * PURPOSE: SaveSortResultss the view list according to DatSaveSortResults().
  73. *
  74. * PARAMETERS: None
  75. *
  76. * RETURNS:
  77. * void
  78. */
  79. void
  80. CViewItemList::SaveSortResults()
  81. {
  82. CViewItemListBase::iterator viewitemiter;
  83. Pviewsortresultsmap()->clear();
  84. for (viewitemiter = begin(); viewitemiter < end(); viewitemiter ++) // create a map of the sort results
  85. {
  86. t_sortmapitem sortmapitem(*viewitemiter, viewitemiter);
  87. Pviewsortresultsmap()->insert(sortmapitem); // This maps the CBaseSnapinItem *'s onto their location in the sorted array.
  88. }
  89. }
  90. /* CViewItemList::ScCompare
  91. *
  92. * PURPOSE:
  93. *
  94. * PARAMETERS:
  95. * CBaseSnapinItem * pitem1:
  96. * CBaseSnapinItem * pitem2:
  97. *
  98. * RETURNS:
  99. * INT
  100. */
  101. INT
  102. CViewItemList::Compare(CBaseSnapinItem * pitem1, CBaseSnapinItem *pitem2)
  103. {
  104. SC sc = S_OK;
  105. INT result = 0; // initialize to "=="
  106. CViewSortResultsMap:: iterator sortresultsiterator1, sortresultsiterator2;
  107. sortresultsiterator1 = Pviewsortresultsmap()->find(pitem1); // locate the iterators for the items
  108. sortresultsiterator2 = Pviewsortresultsmap()->find(pitem2);
  109. if (sortresultsiterator1 == Pviewsortresultsmap()->end() || sortresultsiterator2 == Pviewsortresultsmap()->end())
  110. goto Cleanup; // didn't find, use "=="
  111. result = sortresultsiterator1->second - sortresultsiterator2->second; // fast compare based on indexes.
  112. Cleanup:
  113. return result;
  114. }
  115. /* CViewItemList::Invalidate
  116. *
  117. * PURPOSE:
  118. *
  119. * PARAMETERS:
  120. *
  121. * RETURNS:
  122. * void
  123. */
  124. void
  125. CViewItemList::Invalidate()
  126. {
  127. m_fValid = FALSE;
  128. clear();
  129. }