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.

149 lines
3.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. TREEITER.HXX
  7. DFS Iterator for the generic tree package
  8. This file implements a DFS iterator for the generic tree package (see
  9. tree.hxx & tree.cxx).
  10. Usage:
  11. #include <tree.hxx>
  12. #include <treeiter.hxx>
  13. DECLARE_TREE_OF(TEST);
  14. DECLARE_DFSITER_TREE_OF(TEST);
  15. VOID main()
  16. {
  17. TEST * pTest = new TEST;
  18. pTest->Set(20);
  19. TREE_OF_TEST treeTest( pTest );
  20. for ( int i = 0; i < 10; i++ )
  21. {
  22. TREE_OF_TEST *ptreeTest = new TREE_OF_TEST( new TEST( i ) );
  23. if ( ptreeTest != NULL )
  24. if ( ptreeTest->QueryProp() != NULL )
  25. treeTest.JoinSubtreeLeft( ptreeTest );
  26. else
  27. delete ptreeTest;
  28. }
  29. DFSITER_TREE_OF_TEST dfsitertreeTest( treeTest, 5 );
  30. while ( ( pTest = dfsitertreeTest()) != NULL )
  31. pTest->Print();
  32. }
  33. FILE HISTORY:
  34. Johnl Oct. 15, 1990 Created
  35. */
  36. #if !defined(_TREEITER_HXX_)
  37. #define _TREEITER_HXX_
  38. /*************************************************************************
  39. NAME: DFSITER_TREE
  40. SYNOPSIS: DFS Iter for generic tree class
  41. INTERFACE:
  42. DFSITER_TREE()
  43. Create an iterator starting on this tree node and
  44. traverse to a max depth of usDepth in a DFS fashion.
  45. DFSITER_TREE()
  46. Create a new iterator using the passed iterator's pos.
  47. and depth.
  48. ~DFSITER_TREE()
  49. Destructor
  50. Reset()
  51. Reset this iterators position and depth info.
  52. Next()
  53. Return the Next node in the DFS iteration, returns NULL
  54. when there are no more nodes to return
  55. operator()()
  56. Synonym for Next()
  57. USES: TREE
  58. HISTORY:
  59. Johnl 06-Sep-1990 Created
  60. beng 26-Sep-1991 C7 delta
  61. KeithMo 09-Oct-1991 Win32 Conversion.
  62. **************************************************************************/
  63. DLL_CLASS DFSITER_TREE
  64. {
  65. public:
  66. DFSITER_TREE( const TREE * pt, const UINT uDepth );
  67. DFSITER_TREE( const DFSITER_TREE * pdfsitertree );
  68. ~DFSITER_TREE();
  69. VOID Reset();
  70. VOID* Next();
  71. VOID* operator()() { return Next(); }
  72. protected:
  73. const TREE * QueryNode() const { return _ptreeCurrent; }
  74. const TREE * QueryStartNode() const { return _ptreeStart; }
  75. UINT QueryMaxDepth() const { return _uMaxDepth; }
  76. UINT QueryCurDepth() const { return _uCurDepth; }
  77. private:
  78. const TREE * _ptreeCurrent, *_ptreeStart;
  79. UINT _uMaxDepth, _uCurDepth;
  80. VOID SetNode( const TREE * pt )
  81. { _ptreeCurrent = pt; }
  82. VOID SetStartNode( const TREE * pt )
  83. { _ptreeStart = pt; }
  84. VOID SetMaxDepth( const UINT uMaxDepth )
  85. { _uMaxDepth = uMaxDepth; }
  86. VOID SetCurDepth( const UINT uCurDepth )
  87. { _uCurDepth = uCurDepth; }
  88. };
  89. #define DFSITER_TREE_OF(type) DFSITER_TREE_OF_##type
  90. #define DECL_DFSITER_TREE_OF(type,dec) \
  91. class dec DFSITER_TREE_OF(type) : public DFSITER_TREE \
  92. { \
  93. public: \
  94. DFSITER_TREE_OF(type)( const TREE_OF(type) * pt, \
  95. const UINT uDepth = (UINT)-1) \
  96. : DFSITER_TREE( pt, uDepth ) {; } \
  97. DFSITER_TREE_OF(type)( const DFSITER_TREE_OF(type) * pdfsiter ) \
  98. : DFSITER_TREE( pdfsiter ) {; } \
  99. ~DFSITER_TREE_OF(type)() {; } \
  100. \
  101. type* Next() \
  102. { return (type *)DFSITER_TREE::Next(); } \
  103. \
  104. type* operator()() \
  105. { return Next(); } \
  106. };
  107. #define DECLARE_DFSITER_TREE_OF(type) \
  108. DECL_DFSITER_TREE_OF(type,DLL_TEMPLATE)
  109. #endif