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