Lists.inl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef SE_INCL_LISTS_INL
  2. #define SE_INCL_LISTS_INL
  3. #ifdef PRAGMA_ONCE
  4. #pragma once
  5. #endif
  6. /* Default constructor */
  7. inline CListNode::CListNode(void)
  8. {
  9. // make a non-linked node
  10. ln_Succ = NULL;
  11. ln_Pred = NULL;
  12. }
  13. /* Copy constructor */
  14. inline CListNode::CListNode(const CListNode &lnOriginal)
  15. {
  16. (void) lnOriginal;
  17. // make a non-linked node
  18. ln_Succ = NULL;
  19. ln_Pred = NULL;
  20. }
  21. /* Destructor */
  22. inline CListNode::~CListNode(void)
  23. {
  24. // if node is linked
  25. if (IsLinked()) {
  26. // remove it from list
  27. Remove();
  28. }
  29. }
  30. /* Assignment. */
  31. inline CListNode &CListNode::operator=(const CListNode &lnOriginal)
  32. {
  33. (void) lnOriginal;
  34. // make a non-linked node
  35. ln_Succ = NULL;
  36. ln_Pred = NULL;
  37. return *this;
  38. }
  39. /* Get successor of this node. */
  40. inline CListNode &CListNode::Succ(void) const
  41. {
  42. ASSERT(IsLinked() && ln_Succ->IsLinked());
  43. return *ln_Succ;
  44. }
  45. /* Get predeccessor of this node. */
  46. inline CListNode &CListNode::Pred(void) const
  47. {
  48. ASSERT(IsLinked() && ln_Pred->IsLinked());
  49. return *ln_Pred;
  50. }
  51. /* Get successor of this node for iteration. */
  52. inline CListNode &CListNode::IterationSucc(void) const
  53. {
  54. ASSERT(ln_Succ->IsTailMarker() || ln_Succ->IsLinked());
  55. return *ln_Succ;
  56. }
  57. /* Get predecessor of this node for iteration. */
  58. inline CListNode &CListNode::IterationPred(void) const
  59. {
  60. ASSERT(ln_Pred->IsHeadMarker() || ln_Pred->IsLinked());
  61. return *ln_Pred;
  62. }
  63. /* Insert a node after current one during iteration. */
  64. inline void CListNode::IterationInsertAfter(CListNode &lnNew)
  65. {
  66. ASSERT(!lnNew.IsLinked());
  67. ASSERT(ln_Succ->IsTailMarker() || ln_Succ->IsLinked());
  68. ln_Succ->ln_Pred = &lnNew;
  69. lnNew.ln_Succ = ln_Succ;
  70. lnNew.ln_Pred = this;
  71. ln_Succ = &lnNew;
  72. }
  73. /* Insert a node before current one during iteration. */
  74. inline void CListNode::IterationInsertBefore(CListNode &lnNew)
  75. {
  76. ASSERT(!lnNew.IsLinked());
  77. ASSERT(ln_Pred->IsHeadMarker() || ln_Pred->IsLinked());
  78. ln_Pred->ln_Succ = &lnNew;
  79. lnNew.ln_Pred = ln_Pred;
  80. lnNew.ln_Succ = this;
  81. ln_Pred = &lnNew;
  82. }
  83. /* Check that this list node is head marker of list. */
  84. inline BOOL CListNode::IsHeadMarker(void) const
  85. {
  86. // if this is in fact pointer to list.lh_Head
  87. if (ln_Pred == NULL ) {
  88. // it is end marker
  89. return TRUE;
  90. // otherwise
  91. } else {
  92. // it must be somewhere inside the list
  93. ASSERT(IsLinked());
  94. return FALSE;
  95. }
  96. }
  97. /* Check that this list node is tail marker of list. */
  98. inline BOOL CListNode::IsTailMarker(void) const
  99. {
  100. // if this is in fact pointer to list.lh_NULL
  101. if (ln_Succ == NULL ) {
  102. // it is end marker
  103. return TRUE;
  104. // otherwise
  105. } else {
  106. // it must be somewhere inside the list
  107. ASSERT(IsLinked());
  108. return FALSE;
  109. }
  110. }
  111. /* Check if this list node is head of list. */
  112. inline BOOL CListNode::IsHead(void) const
  113. {
  114. // it must be somewhere inside the list
  115. ASSERT(IsLinked());
  116. // if previous is list.lh_Head
  117. return ln_Pred->ln_Pred == NULL;
  118. }
  119. /* Check that this list node is tail of list. */
  120. inline BOOL CListNode::IsTail(void) const
  121. {
  122. // it must be somewhere inside the list
  123. ASSERT(IsLinked());
  124. // if next is list.lh_NULL
  125. return ln_Succ->ln_Succ == NULL;
  126. }
  127. /////////////////////////////////////////////////////////////////////
  128. // CListHead implementations
  129. /* Get list head. */
  130. inline CListNode &CListHead::Head(void) const
  131. {
  132. ASSERT(IsValid() && lh_Head->IsLinked());
  133. return *lh_Head;
  134. }
  135. /* Get list tail. */
  136. inline CListNode &CListHead::Tail(void) const
  137. {
  138. ASSERT(IsValid() && lh_Tail->IsLinked());
  139. return *lh_Tail;
  140. }
  141. /* Get list head for iteration. */
  142. inline CListNode &CListHead::IterationHead(void) const
  143. {
  144. ASSERT(IsValid() && (lh_Head->IsTailMarker() || lh_Head->IsLinked()));
  145. return *lh_Head;
  146. }
  147. /* Get list tail for iteration. */
  148. inline CListNode &CListHead::IterationTail(void) const
  149. {
  150. ASSERT(IsValid() && (lh_Tail->IsHeadMarker() || lh_Tail->IsLinked()));
  151. return *lh_Tail;
  152. }
  153. #endif /* include-once check. */