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.

132 lines
2.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: ntree.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // NTREE.H
  12. //
  13. #if !defined(_NTREE_H_)
  14. #define _NTREE_H_
  15. #include <functional>
  16. #include "gelem.h"
  17. #include "glnkenum.h"
  18. class NTELEM;
  19. class NTREE;
  20. class NTELEM : public GLNKEL
  21. {
  22. public:
  23. // Internal class for chains (doubly-linked lists) of tree nodes
  24. typedef XCHN<NTELEM> CHN;
  25. // Sort helper "less" binary function class
  26. class SRTFNC : public binary_function<const NTELEM *, const NTELEM *, bool>
  27. {
  28. public:
  29. virtual bool operator () (const NTELEM * pa, const NTELEM * pb) const
  30. { return pa->ICompare( pb ) < 0; }
  31. };
  32. static SRTFNC srtpntelem;
  33. public:
  34. NTELEM ();
  35. virtual ~ NTELEM ();
  36. // Accessor for chain of siblings
  37. CHN & ChnSib ()
  38. { return (CHN &) Chn() ; }
  39. virtual INT EType () const
  40. { return _pnteChild ? EGELM_BRANCH : EGELM_LEAF ; }
  41. // Adopt (link) a child
  42. void Adopt ( NTELEM * pnteChild, bool bSort = false ) ;
  43. // Disown (release) a child
  44. void Disown ( NTELEM * pnteChild ) ;
  45. // Become an orphan
  46. void Orphan () ;
  47. INT ChildCount () ;
  48. INT SiblingCount ();
  49. NTELEM * PnteChild ( INT index ) ;
  50. NTELEM * PnteParent ()
  51. { return _pnteParent; }
  52. NTELEM * PnteChild ()
  53. { return _pnteChild; }
  54. bool BIsChild ( NTELEM * pnte ) ;
  55. // Return the sort value of *this versus another COBJ
  56. virtual INT ICompare ( const NTELEM * pnteOther ) const = 0;
  57. void ReorderChildren ( SRTFNC & fSortRoutine = srtpntelem ) ;
  58. protected:
  59. NTELEM * _pnteParent; // Pointer to single parent (or NULL)
  60. NTELEM * _pnteChild; // Pointer to one child (or NULL)
  61. HIDE_UNSAFE(NTELEM);
  62. };
  63. class NTREE : public NTELEM
  64. {
  65. public:
  66. NTREE ();
  67. virtual ~ NTREE ();
  68. virtual INT EType () const
  69. { return EGELM_TREE ; }
  70. HIDE_UNSAFE(NTREE);
  71. };
  72. template <class T, bool bAnchor>
  73. class NTENUM : public GLNKENUM<T,bAnchor>
  74. {
  75. public:
  76. NTENUM (const T & ntel, bool bIsAnchor = bAnchor, bool iDir = true)
  77. : GLNKENUM<T,bAnchor>( ntel, bIsAnchor, iDir )
  78. {}
  79. // Position to the next pointer
  80. T * PntelNext ()
  81. { return (T *) GLNKENUM<T,bAnchor>::PlnkelNext() ; }
  82. // Return the current object pointer
  83. T * PntelCurrent()
  84. { return (T *) _plnkelNext ; }
  85. // Set the enumerator to have a new base
  86. void Reset ( const T & ntel, int iDir = -1 )
  87. { GLNKENUM<T,bAnchor>::Reset( ntel, iDir ) ; }
  88. };
  89. // Template for generating nested tree motion accessor class
  90. template<class T>
  91. class TWALKER
  92. {
  93. public:
  94. TWALKER ( T & t )
  95. : _pt(&t)
  96. {}
  97. void Reset ( T & t )
  98. { _pt = &t; }
  99. T * PlnkchnPrev ()
  100. { return PdynCast( _pt->Chn().PgelemPrev(), _pt ); }
  101. T * PlnkchnNext ()
  102. { return PdynCast( _pt->Chn().PgelemNext(), _pt ); }
  103. T * Pparent ()
  104. { return PdynCast( _pt->PnteParent(), _pt ); }
  105. T * Pchild ()
  106. { return PdynCast( _pt->PnteChild(), _pt ); }
  107. protected:
  108. T * _pt;
  109. };
  110. #endif