1 // $Id: Intrusive_List.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #ifndef ACE_INTRUSIVE_LIST_CPP
4 #define ACE_INTRUSIVE_LIST_CPP
6 #include "ace/Intrusive_List.h"
8 #if !defined (ACE_LACKS_PRAGMA_ONCE)
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #if !defined (__ACE_INLINE__)
13 #include "ace/Intrusive_List.inl"
14 #endif /* __ACE_INLINE__ */
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 ACE_Intrusive_List
<T
>::ACE_Intrusive_List (void)
26 ACE_Intrusive_List
<T
>::~ACE_Intrusive_List (void)
30 template<class T
> void
31 ACE_Intrusive_List
<T
>::push_back (T
*node
)
42 this->tail_
->next (node
);
43 node
->prev (this->tail_
);
48 template<class T
> void
49 ACE_Intrusive_List
<T
>::push_front (T
*node
)
60 this->head_
->prev (node
);
61 node
->next (this->head_
);
67 ACE_Intrusive_List
<T
>::pop_front (void)
69 T
*node
= this->head_
;
72 this->unsafe_remove (node
);
77 ACE_Intrusive_List
<T
>::pop_back (void)
79 T
*node
= this->tail_
;
82 this->unsafe_remove (node
);
86 template<class T
> void
87 ACE_Intrusive_List
<T
>::remove (T
*node
)
89 for (T
*i
= this->head_
; i
!= 0; i
= i
->next ())
93 this->unsafe_remove (node
);
99 template<class T
> void
100 ACE_Intrusive_List
<T
>::unsafe_remove (T
*node
)
102 if (node
->prev () != 0)
103 node
->prev ()->next (node
->next ());
105 this->head_
= node
->next ();
107 if (node
->next () != 0)
108 node
->next ()->prev (node
->prev ());
110 this->tail_
= node
->prev ();
117 template<class T
> void
118 ACE_Intrusive_List_Node
<T
>::check_invariants (void)
120 ACE_ASSERT ((this->next () == 0) || (this->next ()->prev () == this));
121 ACE_ASSERT ((this->prev () == 0) || (this->prev ()->next () == this));
124 template<class T
> void
125 ACE_Intrusive_List
<T
>::check_invariants (void)
127 ACE_ASSERT ((this->tail_
== 0) || (this->tail_
->next () == 0));
128 ACE_ASSERT ((this->head_
== 0) || (this->head_
->prev () == 0));
129 ACE_ASSERT (!((this->head_
== 0) ^ (this->tail_
== 0)));
132 for (T
*i
= this->head_
; i
!= 0; i
= i
->next ())
134 if (i
== this->tail_
)
136 i
->check_invariants ();
138 ACE_ASSERT (this->tail_
== 0 || found_tail
== 1);
141 for (T
*j
= this->tail_
; j
!= 0; j
= j
->prev ())
143 if (j
== this->head_
)
145 j
->check_invariants ();
147 ACE_ASSERT (this->head_
== 0 || found_head
== 1);
151 ACE_END_VERSIONED_NAMESPACE_DECL
153 #endif /* ACE_INTRUSIVE_LIST_CPP */