#ifndef _T_JPtrArrayIterator
#define _T_JPtrArrayIterator

/******************************************************************************
 JPtrArrayIterator.tmpl

						The Pointer Array Iterator Class

	Provides a consistent interface for iterating over a JPtrArray.

	Refer to JOrderedSetIterator.tmpl for information about interators in general.

	Copyright © 1994-97 by John Lindal. All rights reserved.

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

#include <JPtrArrayIterator.h>
#include <JPtrArray.h>
#include <jAssert.h>

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

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

template <class T>
JPtrArrayIterator<T>::JPtrArrayIterator
	(
	const JPtrArray<T>&		theArray,
	const JIteratorPosition	start,
	const JIndex			index
	)
	:
	JOrderedSetIterator<T*>(theArray, start, index)
{
}

template <class T>
JPtrArrayIterator<T>::JPtrArrayIterator
	(
	JPtrArray<T>*			theArray,
	const JIteratorPosition	start,
	const JIndex			index
	)
	:
	JOrderedSetIterator<T*>(theArray, start, index)
{
}

/******************************************************************************
 DeletePrev (virtual)

	Returns kTrue if we have a non-const JOrderedSet<T>* and
	there is a previous item.

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

template <class T>
JBoolean
JPtrArrayIterator<T>::DeletePrev()
{
	JOrderedSet<T*>* obj;
	if (!GetOrderedSet(&obj) || AtBeginning())
		{
		return kFalse;
		}

	JPtrArray<T>* ptr = dynamic_cast(JPtrArray<T>*, obj);
	assert( ptr != NULL );

	ptr->DeleteElement(GetCursor());
	return kTrue;
}

/******************************************************************************
 DeleteNext (virtual)

	Returns kTrue if we have a non-const JOrderedSet<T>* and
	there is a next item.

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

template <class T>
JBoolean
JPtrArrayIterator<T>::DeleteNext()
{
	JOrderedSet<T*>* obj;
	if (!GetOrderedSet(&obj) || AtEnd())
		{
		return kFalse;
		}

	JPtrArray<T>* ptr = dynamic_cast(JPtrArray<T>*, obj);
	assert( ptr != NULL );

	ptr->DeleteElement(GetCursor()+1);
	return kTrue;
}

#endif

// Instantiate the template for the specified type.

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