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.

101 lines
2.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: glnkenum.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // GLNKENUM.H
  12. //
  13. #if !defined(_GLNKENUM_H_)
  14. #define _GLNKENUM_H_
  15. // Base class for generic linkable object enumerators
  16. class GLNKENUM_BASE
  17. {
  18. public:
  19. // Construct an enumerator.
  20. GLNKENUM_BASE ( const GLNKEL & lnkel, int iDir = 1 )
  21. {
  22. Reset( lnkel, iDir ) ;
  23. }
  24. // Position to the next pointer
  25. GLNKEL * PlnkelNext () ;
  26. // Return the current object pointer
  27. inline GLNKEL * PlnkelCurrent()
  28. { return _plnkelNext ; }
  29. // Set the enumerator to have a new base
  30. void Reset ( const GLNKEL & lnkel, int iDir = 0 )
  31. {
  32. _plnkelStart = const_cast<GLNKEL *>(& lnkel) ;
  33. _plnkelNext = NULL ;
  34. if ( iDir >= 0 )
  35. _iDir = iDir ;
  36. }
  37. protected:
  38. GLNKEL * _plnkelStart ;
  39. GLNKEL * _plnkelNext ;
  40. int _iDir ; // Enumeration direction
  41. };
  42. #define BOOL_CROSS_PRODUCT(a,b) (((a) > 0) + (((b) > 0) * 2))
  43. inline
  44. GLNKEL * GLNKENUM_BASE :: PlnkelNext ()
  45. {
  46. GLNKEL * plnkelResult = NULL ;
  47. switch ( BOOL_CROSS_PRODUCT( _plnkelNext != NULL, _iDir ) )
  48. {
  49. case BOOL_CROSS_PRODUCT( true, true ):
  50. if ( _plnkelNext->PlnkelNext() != _plnkelStart )
  51. plnkelResult =_plnkelNext = _plnkelNext->PlnkelNext() ;
  52. break ;
  53. case BOOL_CROSS_PRODUCT( true, false ):
  54. if ( _plnkelNext != _plnkelStart )
  55. plnkelResult = _plnkelNext = _plnkelNext->PlnkelPrev() ;
  56. break ;
  57. case BOOL_CROSS_PRODUCT( false, true ):
  58. plnkelResult = _plnkelNext = _plnkelStart ;
  59. break ;
  60. case BOOL_CROSS_PRODUCT( false, false ):
  61. plnkelResult = _plnkelNext = _plnkelStart->PlnkelPrev() ;
  62. break ;
  63. }
  64. return plnkelResult ;
  65. }
  66. template <class L, bool bAnchor>
  67. class GLNKENUM : public GLNKENUM_BASE
  68. {
  69. public:
  70. // Construct an enumerator. If 'bAnchor', then the anchor object is
  71. // skipped during enumeration.
  72. GLNKENUM ( const L & lnkel, bool bIsAnchor = bAnchor, int iDir = 1 )
  73. : GLNKENUM_BASE( lnkel, iDir )
  74. {
  75. if ( bIsAnchor )
  76. PlnkelNext() ;
  77. }
  78. // Position to the next pointer
  79. L * PlnkelNext ()
  80. { return (L *) GLNKENUM_BASE::PlnkelNext() ; }
  81. // Return the current object pointer
  82. L * PlnkelCurrent()
  83. { return (L *) _plnkelNext ; }
  84. // Set the enumerator to have a new base
  85. void Reset ( const L & lnkel, int iDir = -1 )
  86. { GLNKENUM_BASE::Reset( lnkel, iDir ) ; }
  87. };
  88. #endif