/** * @file XTPMarkupTypedSimpleStack.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPMARKUPTYPEDSIMPLESTACK_H__) # define __XTPMARKUPTYPEDSIMPLESTACK_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" template class CXTPMarkupTypedSimpleStack { public: CXTPMarkupTypedSimpleStack() { m_pHead = NULL; m_pTail = NULL; } BOOL IsEmpty() const { return m_pHead == NULL; } void AddTail(TYPE* pPart) { if (m_pTail != NULL) { m_pTail->m_pNextChain = pPart; } else { m_pTail = m_pHead = pPart; } m_pTail = pPart; } void AddHead(TYPE* pPart) { if (m_pHead != NULL) { pPart->m_pNextChain = m_pHead; m_pHead = pPart; } else { m_pTail = m_pHead = pPart; } } TYPE* RemoveHead() { if (NULL == m_pHead) return NULL; TYPE* pHead = m_pHead; if (m_pHead == m_pTail) { m_pHead = m_pTail = NULL; } else { m_pHead = pHead->m_pNextChain; _ASSERTE(NULL != m_pHead); } pHead->m_pNextChain = NULL; return pHead; } TYPE* GetHead() const { return m_pHead; } TYPE* GetTail() const { return m_pTail; } BOOL Remove(TYPE* p) { _ASSERTE(p != NULL); if (!p) return FALSE; if (m_pHead == m_pTail) { if (p != m_pHead) return FALSE; p->m_pNextChain = NULL; m_pHead = m_pTail = NULL; return TRUE; } if (m_pHead == p) { m_pHead = p->m_pNextChain; p->m_pNextChain = NULL; return TRUE; } TYPE* pTest = m_pHead; while (pTest != NULL && pTest->m_pNextChain != p) pTest = pTest->m_pNextChain; if (pTest != NULL) { if (m_pTail == p) m_pTail = pTest; pTest->m_pNextChain = p->m_pNextChain; p->m_pNextChain = NULL; return TRUE; } return FALSE; } protected: TYPE* m_pHead; TYPE* m_pTail; }; # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPMARKUPTYPEDSIMPLESTACK_H__) /** @endcond */