13 ListItem ( T* pItem ) : m_pItem(pItem), m_prev(NULL), m_next(NULL)
17 T* GetItem () {
return m_pItem; }
19 ListItem* GetPrev () {
return m_prev; }
20 ListItem* GetNext () {
return m_next; }
22 void SetPrev (
ListItem* pPrev ) { m_prev = pPrev; }
23 void SetNext (
ListItem* pNext ) { m_next = pNext; }
41 T* GetHead () {
return m_head; }
42 T* GetTail () {
return m_tail; }
43 u32 GetLength () {
return m_length; }
45 void AddToHead ( T* item );
46 void AddToTail ( T* item );
48 void InsertBefore( T* item, T* listItem );
49 void InsertAfter ( T* item, T* listItem );
67 void List<T>::AddToHead ( T* item )
70 item->SetNext(m_head);
74 m_head->SetPrev(item);
86 void List<T>::AddToTail ( T* item )
88 item->SetPrev(m_tail);
93 m_tail->SetNext(item);
104 template <
typename T>
105 void List<T>::InsertBefore( T* item, T* listItem )
107 item->SetPrev(listItem->GetPrev());
108 item->SetNext(listItem);
110 if(listItem->GetPrev())
112 listItem->GetPrev()->SetNext(item);
115 listItem->SetPrev(item);
117 if(m_head == listItem)
125 template <
typename T>
126 void List<T>::InsertAfter ( T* item, T* listItem )
128 item->SetPrev(listItem);
129 item->SetNext(listItem->GetNext());
131 if(listItem->GetNext())
133 listItem->GetNext()->SetPrev(item);
136 listItem->SetNext(item);
138 if(m_tail == listItem)
146 template <
typename T>
147 T* List<T>::RemoveHead ()
153 if(m_head->GetNext())
155 m_head->GetNext()->SetPrev(NULL);
163 m_head = m_head->GetNext();
174 template <
typename T>
175 T* List<T>::RemoveTail ()
181 if(m_tail->GetPrev())
183 m_tail->GetPrev()->SetNext(NULL);
191 m_tail = m_tail->GetPrev();
202 template <
typename T>
203 T* List<T>::Remove(T* item)
209 else if(m_tail == item)
217 item->GetPrev()->SetNext(item->GetNext());
222 item->GetNext()->SetPrev(item->GetPrev());