[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Intrusive_List.cpp
blobbdb17837d646dc06152403cc0a2345a80f825138
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)
9 # 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
18 template <class T>
19 ACE_Intrusive_List<T>::ACE_Intrusive_List (void)
20 : head_ (0)
21 , tail_ (0)
25 template<class T>
26 ACE_Intrusive_List<T>::~ACE_Intrusive_List (void)
30 template<class T> void
31 ACE_Intrusive_List<T>::push_back (T *node)
33 if (this->tail_ == 0)
35 this->tail_ = node;
36 this->head_ = node;
37 node->next (0);
38 node->prev (0);
39 return;
42 this->tail_->next (node);
43 node->prev (this->tail_);
44 node->next (0);
45 this->tail_ = node;
48 template<class T> void
49 ACE_Intrusive_List<T>::push_front (T *node)
51 if (this->head_ == 0)
53 this->tail_ = node;
54 this->head_ = node;
55 node->next (0);
56 node->prev (0);
57 return;
60 this->head_->prev (node);
61 node->next (this->head_);
62 node->prev (0);
63 this->head_ = node;
66 template<class T> T *
67 ACE_Intrusive_List<T>::pop_front (void)
69 T *node = this->head_;
70 if (node == 0)
71 return 0;
72 this->unsafe_remove (node);
73 return node;
76 template<class T> T *
77 ACE_Intrusive_List<T>::pop_back (void)
79 T *node = this->tail_;
80 if (node == 0)
81 return 0;
82 this->unsafe_remove (node);
83 return 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 ())
91 if (node == i)
93 this->unsafe_remove (node);
94 return;
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 ());
104 else
105 this->head_ = node->next ();
107 if (node->next () != 0)
108 node->next ()->prev (node->prev ());
109 else
110 this->tail_ = node->prev ();
112 node->next (0);
113 node->prev (0);
116 #if 0
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)));
131 int found_tail = 0;
132 for (T *i = this->head_; i != 0; i = i->next ())
134 if (i == this->tail_)
135 found_tail = 1;
136 i->check_invariants ();
138 ACE_ASSERT (this->tail_ == 0 || found_tail == 1);
140 int found_head = 0;
141 for (T *j = this->tail_; j != 0; j = j->prev ())
143 if (j == this->head_)
144 found_head = 1;
145 j->check_invariants ();
147 ACE_ASSERT (this->head_ == 0 || found_head == 1);
149 #endif /* 0 */
151 ACE_END_VERSIONED_NAMESPACE_DECL
153 #endif /* ACE_INTRUSIVE_LIST_CPP */