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.

142 lines
3.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // StlUtils.h
  7. //
  8. // Abstract:
  9. // Definition of STL utility classes and functions.
  10. //
  11. // Implementation File:
  12. // None.
  13. //
  14. // Author:
  15. // David Potter (davidp) May 21, 1998
  16. //
  17. // Revision History:
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #ifndef __STLUTUILS_H_
  23. #define __STLUTUILS_H_
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Forward Class Declarations
  26. /////////////////////////////////////////////////////////////////////////////
  27. /////////////////////////////////////////////////////////////////////////////
  28. // External Class Declarations
  29. /////////////////////////////////////////////////////////////////////////////
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Include Files
  32. /////////////////////////////////////////////////////////////////////////////
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Type Definitions
  35. /////////////////////////////////////////////////////////////////////////////
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Global Functions
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Delete all items from a pointer list
  40. template < class T >
  41. void DeleteAllPtrListItems( std::list< T > * pList )
  42. {
  43. ATLASSERT( pList != NULL );
  44. //
  45. // Get pointers to beginning and end of list.
  46. //
  47. std::list< T >::iterator itCurrent = pList->begin();
  48. std::list< T >::iterator itLast = pList->end();
  49. //
  50. // Loop through the list and delete each objects.
  51. //
  52. while ( itCurrent != itLast )
  53. {
  54. T pT = *itCurrent;
  55. ATLASSERT( pT != NULL );
  56. delete pT;
  57. itCurrent = pList->erase( itCurrent );
  58. } // while: more items in the list
  59. } //*** DeleteAllPtrListItems()
  60. // Delete items of a desired type from a pointer list
  61. template < class TBase, class T >
  62. void DeletePtrListItems( std::list< TBase > * pList )
  63. {
  64. ATLASSERT( pList != NULL );
  65. //
  66. // Get pointers to beginning and end of list.
  67. //
  68. std::list< TBase >::iterator itCurrent = pList->begin();
  69. std::list< TBase >::iterator itLast = pList->end();
  70. //
  71. // Loop through the list looking for objects of the
  72. // desired type and delete those objects.
  73. //
  74. while ( itCurrent != itLast )
  75. {
  76. T pT = dynamic_cast< T >( *itCurrent );
  77. if ( pT != NULL )
  78. {
  79. delete pT;
  80. itCurrent = pList->erase( itCurrent );
  81. } // if: object has desired type
  82. else
  83. {
  84. itCurrent++;
  85. } // else: object has different type
  86. } // while: more items in the list
  87. } //*** DeletePtrListItems()
  88. // Move items of a desired type from one pointer list to another list
  89. template < class TBase, class T >
  90. void MovePtrListItems(
  91. std::list< TBase > * pSrcList,
  92. std::list< T > * pDstList
  93. )
  94. {
  95. ATLASSERT( pSrcList != NULL );
  96. ATLASSERT( pDstList != NULL );
  97. //
  98. // Get pointers to beginning and end of list.
  99. //
  100. std::list< TBase >::iterator itCurrent = pSrcList->begin();
  101. std::list< TBase >::iterator itLast = pSrcList->end();
  102. //
  103. // Loop through the source list looking for objects of the
  104. // desired type and move those objects to the
  105. // destination list.
  106. //
  107. while ( itCurrent != itLast )
  108. {
  109. T pT = dynamic_cast< T >( *itCurrent );
  110. if ( pT != NULL )
  111. {
  112. itCurrent = pSrcList->erase( itCurrent );
  113. pDstList->insert( pDstList->end(), pT );
  114. } // if: object has desired type
  115. else
  116. {
  117. itCurrent++;
  118. } // else: object has different type
  119. } // while: more items in the list
  120. } //*** MovePtrListItems()
  121. /////////////////////////////////////////////////////////////////////////////
  122. #endif // __STLUTUILS_H_