#ifndef _T_JPtrQueue
#define _T_JPtrQueue

/******************************************************************************
 JPtrQueue.tmpl

	This class provides extra functions that are useful when storing
	a queue of pointers.

	BASE CLASS = public JQueue<S,T>

	Copyright © 1996-97 John Lindal. All rights reserved.

 ******************************************************************************/

#include <JPtrQueue.h>

/******************************************************************************
 Constructor

 ******************************************************************************/

template <class S, class T>
JPtrQueue<S,T>::JPtrQueue()
	:
	JQueue<S,T>()
{
}

/******************************************************************************
 FlushDelete

	Delete all the elements and remove them from the queue.

 ******************************************************************************/

template <class S, class T>
void
JPtrQueue<S,T>::FlushDelete()
{
	S* list           = GetElements();
	const JSize count = list->GetElementCount();
	for (JIndex i=1; i<=count; i++)
		{
		T elementPtr = list->GetElement(i);
		delete elementPtr;
		}

	Flush();
}

/******************************************************************************
 DiscardDelete

	Delete the first few elements and remove them from the queue.

 ******************************************************************************/

template <class S, class T>
void
JPtrQueue<S,T>::DiscardDelete
	(
	const JSize numToDiscard
	)
{
	S* list           = GetElements();
	const JSize count = list->GetElementCount();
	for (JIndex i=1; i<=numToDiscard && i<=count; i++)
		{
		T elementPtr = list->GetElement(i);
		delete elementPtr;
		}

	Discard(numToDiscard);
}

#endif

// Instantiate the template for the specified type.

#if defined JTemplateType && ! defined JOnlyWantTemplateDefinition
	#define JTemplateName JPtrQueue
	#include <instantiate_template.h>
	#undef JTemplateName
#endif
