123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #pragma once
- #ifndef HACD_CIRCULAR_LIST_INL
- #define HACD_CIRCULAR_LIST_INL
- namespace VHACD
- {
- template < typename T >
- inline bool CircularList<T>::Delete(CircularListElement<T> * element)
- {
- if (!element)
- {
- return false;
- }
- if (m_size > 1)
- {
- CircularListElement<T> * next = element->GetNext();
- CircularListElement<T> * prev = element->GetPrev();
- delete element;
- m_size--;
- if (element == m_head)
- {
- m_head = next;
- }
- next->GetPrev() = prev;
- prev->GetNext() = next;
- return true;
- }
- else if (m_size == 1)
- {
- delete m_head;
- m_size--;
- m_head = 0;
- return true;
- }
- else
- {
- return false;
- }
- }
-
- template < typename T >
- inline bool CircularList<T>::Delete()
- {
- if (m_size > 1)
- {
- CircularListElement<T> * next = m_head->GetNext();
- CircularListElement<T> * prev = m_head->GetPrev();
- delete m_head;
- m_size--;
- m_head = next;
- next->GetPrev() = prev;
- prev->GetNext() = next;
- return true;
- }
- else if (m_size == 1)
- {
- delete m_head;
- m_size--;
- m_head = 0;
- return true;
- }
- else
- {
- return false;
- }
- }
- template < typename T >
- inline CircularListElement<T> * CircularList<T>::Add(const T * data)
- {
- if (m_size == 0)
- {
- if (data)
- {
- m_head = new CircularListElement<T>(*data);
- }
- else
- {
- m_head = new CircularListElement<T>();
- }
- m_head->GetNext() = m_head->GetPrev() = m_head;
- }
- else
- {
- CircularListElement<T> * next = m_head->GetNext();
- CircularListElement<T> * element = m_head;
- if (data)
- {
- m_head = new CircularListElement<T>(*data);
- }
- else
- {
- m_head = new CircularListElement<T>();
- }
- m_head->GetNext() = next;
- m_head->GetPrev() = element;
- element->GetNext() = m_head;
- next->GetPrev() = m_head;
- }
- m_size++;
- return m_head;
- }
- template < typename T >
- inline CircularListElement<T> * CircularList<T>::Add(const T & data)
- {
- const T * pData = &data;
- return Add(pData);
- }
- template < typename T >
- inline bool CircularList<T>::Next()
- {
- if (m_size == 0)
- {
- return false;
- }
- m_head = m_head->GetNext();
- return true;
- }
- template < typename T >
- inline bool CircularList<T>::Prev()
- {
- if (m_size == 0)
- {
- return false;
- }
- m_head = m_head->GetPrev();
- return true;
- }
- template < typename T >
- inline CircularList<T>::CircularList(const CircularList& rhs)
- {
- if (rhs.m_size > 0)
- {
- CircularListElement<T> * current = rhs.m_head;
- do
- {
- current = current->GetNext();
- Add(current->GetData());
- }
- while ( current != rhs.m_head );
- }
- }
- template < typename T >
- inline const CircularList<T>& CircularList<T>::operator=(const CircularList& rhs)
- {
- if (&rhs != this)
- {
- Clear();
- if (rhs.m_size > 0)
- {
- CircularListElement<T> * current = rhs.m_head;
- do
- {
- current = current->GetNext();
- Add(current->GetData());
- }
- while ( current != rhs.m_head );
- }
- }
- return (*this);
- }
- }
- #endif
|