/*++ Copyright (c) 1998 Microsoft Corporation All rights reserved. Module Name: slist.inl Abstract: Single linked list template class. Author: Weihai Chen (WeihaiC) 06/29/98 Revision History: --*/ template CSingleList::CSingleList(void) :m_Dummy () { } template CSingleList::~CSingleList(void) { Lock (); CSingleItem *pItem = m_Dummy.GetNext(); CSingleItem *pNext; while (pItem) { pNext = pItem->GetNext(); delete pItem; pItem = pNext; } Unlock (); } template BOOL CSingleList::Insert (T item) { BOOL bRet = FALSE; Lock(); CSingleItem *pNewItem = new CSingleItem (item, m_Dummy.GetNext()); if (pNewItem) { m_Dummy.SetNext (pNewItem); bRet = TRUE; } Unlock(); return bRet; } template BOOL CSingleList::Delete (T item) { CSingleItem *pHead = &m_Dummy; CSingleItem *pItem; BOOL bRet = FALSE; Lock(); while (pItem = pHead->GetNext()) { if (pItem->IsSame (item)) { // Delete it pHead->SetNext (pItem->GetNext ()); delete (pItem); bRet = TRUE; break; } pHead = pHead->GetNext(); } Unlock(); return FALSE; } template T CSingleList::Find (T item) { Lock(); CSingleItem *pItem = m_Dummy.GetNext(); while (pItem) { if (pItem->IsSame (item)) { Unlock (); return pItem->GetData(); } pItem = pItem->GetNext(); } Unlock (); return NULL; }