// ImageQueue.h: interface for the ImageQueue class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_IMAGEQUEUE_H__894B468B_97A0_47FC_8C85_1B47D5C60DBD__INCLUDED_)
#define AFX_IMAGEQUEUE_H__894B468B_97A0_47FC_8C85_1B47D5C60DBD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "CImage"

//!This class defines a color image Queue that is constant in length after it is created.  
/*!Images that go in are not
created or destoyed following their initial creation.  They cycle through the queue.
This is completely application specific.  I made it because I needed it.  It may not ever be useful for anyone else.
*/
template <class T>
class ImageQueue  
{
public:
	///Initialized the Image Queue to hold images of the size indicated.
	ImageQueue(int size, int x, int y);
	///Reinitializes the Image Queue to hold images of a different size.
	ReMake(int subset, int x, int y);
	virtual ~ImageQueue();
	///Gets the current image (doesn't actually delete, since that takes time), though you'll be looking at the next image the next time you try.
	ColorImage<T> & Pop(); 
	///Returns the image at the top of the queue.
	ColorImage<T> & Look() {return ImageList[currpic];}; 
	///Returns the image in the previous position in the queue.
	ColorImage<T> & Prev() {return ImageList[currpic==0?size-1:currpic-1];}; 
	///Returns the image at the next location in the set
	ColorImage<T> & Next() {return ImageList[(currpic+1) % size];}; //Looks at the next image;
	///Looks at the middle location in a list of images.
	ColorImage<T> & Middle(){return ImageList[int((size %2) + (size/2.0))];};
private:	
	ColorImage<T> *ImageList;
	int size, currpic;
};

template <class T>
ImageQueue<T>::ImageQueue(int size, int x, int y)
{
	ImageList=new ColorImage<T>[size];
	for(int i=0; i<size; i++)
		ImageList[i].SetSize(x,y);
	currpic=0;
}

template <class T>
ImageQueue<T>::ReMake(int subset, int x, int y)
{
	size = subset;
	delete [] ImageList;
	ImageList=new ColorImage<T>[size];
	for(int i=0; i<size; i++)
		ImageList[i].SetSize(x,y);
	currpic=0;
}

template <class T>
ColorImage<T> & ImageQueue<T>::Pop()
{
		int temp=currpic;
		currpic=(currpic +1) %size;
		return ImageList[temp];
}

template <class T>
ImageQueue<T>::~ImageQueue()
{
	delete[] ImageList;
}

#endif // !defined(AFX_IMAGEQUEUE_H__894B468B_97A0_47FC_8C85_1B47D5C60DBD__INCLUDED_)
