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.

198 lines
4.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ClassBilink.h
  6. * Content: Class-based bilink
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 09/17/99 jtk Derived from bilink.c
  13. * 08/15/00 masonb Changed assert to DNASSERT and added DNASSERT(this)
  14. *
  15. ***************************************************************************/
  16. #ifndef __CLASS_BILINK_H__
  17. #define __CLASS_BILINK_H__
  18. #include "dndbg.h"
  19. #undef DPF_SUBCOMP
  20. #define DPF_SUBCOMP DN_SUBCOMP_COMMON
  21. //**********************************************************************
  22. // Constant definitions
  23. //**********************************************************************
  24. //**********************************************************************
  25. // Macro definitions
  26. //**********************************************************************
  27. //**********************************************************************
  28. // Structure definitions
  29. //**********************************************************************
  30. //**********************************************************************
  31. // Variable definitions
  32. //**********************************************************************
  33. //**********************************************************************
  34. // Function Prototypes
  35. //**********************************************************************
  36. //**********************************************************************
  37. // Class definitions
  38. //**********************************************************************
  39. class CBilink
  40. {
  41. public:
  42. CBilink(){};
  43. ~CBilink(){};
  44. #undef DPF_MODNAME
  45. #define DPF_MODNAME "CBilink::Initialize"
  46. void Initialize( void )
  47. {
  48. DNASSERT( this != NULL );
  49. m_pNext = this;
  50. m_pPrev = this;
  51. }
  52. #undef DPF_MODNAME
  53. #define DPF_MODNAME "CBilink::GetNext"
  54. CBilink *GetNext( void ) const
  55. {
  56. DNASSERT( this != NULL );
  57. return m_pNext;
  58. }
  59. #undef DPF_MODNAME
  60. #define DPF_MODNAME "CBilink::GetPrev"
  61. CBilink *GetPrev( void ) const
  62. {
  63. DNASSERT( this != NULL );
  64. return m_pPrev;
  65. }
  66. #undef DPF_MODNAME
  67. #define DPF_MODNAME "CBilink::IsEmpty"
  68. BOOL IsEmpty( void ) const
  69. {
  70. DNASSERT( this != NULL );
  71. DNASSERT( m_pNext != NULL );
  72. if ( ( m_pNext == m_pPrev ) &&
  73. ( m_pNext == this ) )
  74. {
  75. return TRUE;
  76. }
  77. return FALSE;
  78. }
  79. #undef DPF_MODNAME
  80. #define DPF_MODNAME "CBilink::IsListMember"
  81. BOOL IsListMember( const CBilink *const pList ) const
  82. {
  83. CBilink * pTemp;
  84. DNASSERT( this != NULL );
  85. DNASSERT( pList != NULL );
  86. pTemp = pList->GetNext();
  87. while ( pTemp != pList )
  88. {
  89. if ( pTemp == this )
  90. {
  91. return TRUE;
  92. }
  93. pTemp = pTemp->GetNext();
  94. }
  95. return FALSE;
  96. }
  97. #undef DPF_MODNAME
  98. #define DPF_MODNAME "CBilink::InsertAfter"
  99. void InsertAfter( CBilink* const pList )
  100. {
  101. DNASSERT( this != NULL );
  102. DNASSERT( pList->m_pNext != NULL );
  103. DNASSERT( pList->m_pPrev != NULL );
  104. DNASSERT( !IsListMember( pList ) );
  105. m_pNext = pList->m_pNext;
  106. m_pPrev = pList;
  107. pList->m_pNext->m_pPrev = this;
  108. pList->m_pNext = this;
  109. }
  110. #undef DPF_MODNAME
  111. #define DPF_MODNAME "CBilink::InsertBefore"
  112. void InsertBefore( CBilink* const pList )
  113. {
  114. DNASSERT( this != NULL );
  115. DNASSERT( pList->m_pNext != NULL );
  116. DNASSERT( pList->m_pPrev != NULL );
  117. DNASSERT( !IsListMember( pList ) );
  118. m_pNext = pList;
  119. m_pPrev = pList->m_pPrev;
  120. pList->m_pPrev->m_pNext = this;
  121. pList->m_pPrev = this;
  122. }
  123. #undef DPF_MODNAME
  124. #define DPF_MODNAME "CBilink::RemoveFromList"
  125. void RemoveFromList( void )
  126. {
  127. DNASSERT( this != NULL );
  128. DNASSERT( m_pNext != NULL );
  129. DNASSERT( m_pPrev != NULL );
  130. DNASSERT( m_pNext->m_pPrev == this );
  131. DNASSERT( m_pPrev->m_pNext == this );
  132. m_pNext->m_pPrev = m_pPrev;
  133. m_pPrev->m_pNext = m_pNext;
  134. Initialize();
  135. }
  136. #undef DPF_MODNAME
  137. #define DPF_MODNAME "CBilink::AttachListBefore"
  138. void AttachListBefore( CBilink* const pList )
  139. {
  140. CBilink* pAddLast;
  141. DNASSERT( this != NULL );
  142. DNASSERT( pList->m_pNext != NULL );
  143. DNASSERT( pList->m_pPrev != NULL );
  144. DNASSERT( !this->IsListMember( pList ) );
  145. DNASSERT( !pList->IsListMember( this ) );
  146. pAddLast = pList->m_pPrev;
  147. m_pPrev->m_pNext = pList;
  148. pList->m_pPrev = m_pPrev;
  149. m_pPrev = pAddLast;
  150. pAddLast->m_pNext = this;
  151. }
  152. protected:
  153. private:
  154. CBilink *m_pNext;
  155. CBilink *m_pPrev;
  156. };
  157. #undef DPF_MODNAME
  158. #undef DPF_SUBCOMP
  159. #endif // __CLASS_BILINK_H__