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.

183 lines
4.4 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. #ifndef CONTAINING_OBJECT
  28. #define CONTAINING_OBJECT(address, type, field) ((type *)( \
  29. (PCHAR)(address) - \
  30. (UINT_PTR)(&((type *)0)->field)))
  31. #endif // CONTAINING_OBJECT
  32. //**********************************************************************
  33. // Structure definitions
  34. //**********************************************************************
  35. //**********************************************************************
  36. // Variable definitions
  37. //**********************************************************************
  38. //**********************************************************************
  39. // Function Prototypes
  40. //**********************************************************************
  41. //**********************************************************************
  42. // Class definitions
  43. //**********************************************************************
  44. class CBilink
  45. {
  46. public:
  47. CBilink(){};
  48. ~CBilink(){};
  49. #undef DPF_MODNAME
  50. #define DPF_MODNAME "CBilink::Initialize"
  51. void Initialize( void )
  52. {
  53. DNASSERT( this != NULL );
  54. m_pNext = this;
  55. m_pPrev = this;
  56. }
  57. #undef DPF_MODNAME
  58. #define DPF_MODNAME "CBilink::GetNext"
  59. CBilink *GetNext( void ) const
  60. {
  61. DNASSERT( this != NULL );
  62. return m_pNext;
  63. }
  64. #undef DPF_MODNAME
  65. #define DPF_MODNAME "CBilink::GetPrev"
  66. CBilink *GetPrev( void ) const
  67. {
  68. DNASSERT( this != NULL );
  69. return m_pPrev;
  70. }
  71. #undef DPF_MODNAME
  72. #define DPF_MODNAME "CBilink::IsEmpty"
  73. BOOL IsEmpty( void ) const
  74. {
  75. DNASSERT( this != NULL );
  76. DNASSERT( m_pNext != NULL );
  77. if ( ( m_pNext == m_pPrev ) &&
  78. ( m_pNext == this ) )
  79. {
  80. return TRUE;
  81. }
  82. return FALSE;
  83. }
  84. #undef DPF_MODNAME
  85. #define DPF_MODNAME "CBilink::IsListMember"
  86. BOOL IsListMember( const CBilink *const pList ) const
  87. {
  88. CBilink * pTemp;
  89. DNASSERT( this != NULL );
  90. DNASSERT( pList != NULL );
  91. pTemp = pList->GetNext();
  92. while ( pTemp != pList )
  93. {
  94. if ( pTemp == this )
  95. {
  96. return TRUE;
  97. }
  98. pTemp = pTemp->GetNext();
  99. }
  100. return FALSE;
  101. }
  102. #undef DPF_MODNAME
  103. #define DPF_MODNAME "CBilink::InsertAfter"
  104. void InsertAfter( CBilink* const pList )
  105. {
  106. DNASSERT( this != NULL );
  107. DNASSERT( pList->m_pNext != NULL );
  108. DNASSERT( pList->m_pPrev != NULL );
  109. DNASSERT( !IsListMember( pList ) );
  110. DNASSERT( IsEmpty() );
  111. m_pNext = pList->m_pNext;
  112. m_pPrev = pList;
  113. pList->m_pNext->m_pPrev = this;
  114. pList->m_pNext = this;
  115. }
  116. #undef DPF_MODNAME
  117. #define DPF_MODNAME "CBilink::InsertBefore"
  118. void InsertBefore( CBilink* const pList )
  119. {
  120. DNASSERT( this != NULL );
  121. DNASSERT( pList->m_pNext != NULL );
  122. DNASSERT( pList->m_pPrev != NULL );
  123. DNASSERT( !IsListMember( pList ) );
  124. DNASSERT( IsEmpty() );
  125. m_pNext = pList;
  126. m_pPrev = pList->m_pPrev;
  127. pList->m_pPrev->m_pNext = this;
  128. pList->m_pPrev = this;
  129. }
  130. #undef DPF_MODNAME
  131. #define DPF_MODNAME "CBilink::RemoveFromList"
  132. void RemoveFromList( void )
  133. {
  134. DNASSERT( this != NULL );
  135. DNASSERT( m_pNext != NULL );
  136. DNASSERT( m_pPrev != NULL );
  137. DNASSERT( m_pNext->m_pPrev == this );
  138. DNASSERT( m_pPrev->m_pNext == this );
  139. m_pNext->m_pPrev = m_pPrev;
  140. m_pPrev->m_pNext = m_pNext;
  141. Initialize();
  142. }
  143. private:
  144. CBilink *m_pNext;
  145. CBilink *m_pPrev;
  146. };
  147. #undef DPF_MODNAME
  148. #undef DPF_SUBCOMP
  149. #endif // __CLASS_BILINK_H__