// Fifo.h: interface for the Fifo class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FIFO_H__30DBFB73_C999_11D3_A1B8_0000F8707EB9__INCLUDED_)
#define AFX_FIFO_H__30DBFB73_C999_11D3_A1B8_0000F8707EB9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <malloc.h>
#include <stdio.h>

class Fifo  
{
public:
	Fifo(int siz = 200);
	virtual ~Fifo() { free(fifo); };

	void  add(unsigned char newval) { fifo[iter]=newval; if (++iter>(size-1)) iter=0;};
	unsigned char getcur() { return fifo[((iter==0)?(size-1):(iter-1))]; };
	void  clear() {for (int i=0; i<size; i++) fifo[i]=0; iter=0;};
	float std();
	float mean();
	unsigned char  getmax();
	unsigned char getmin();
	unsigned char  peeksize(); // get stepsize
	unsigned char  peekrate(); // get steprate

	void setsize(int siz) {size = siz; free(fifo); fifo = (unsigned char*) malloc(sizeof(unsigned char)*size); };

	void printout(char* fn); // prints out the entire array

private:
	unsigned char	*fifo;
	int	iter;  // iterator
	int	size;
};

#endif // !defined(AFX_FIFO_H__30DBFB73_C999_11D3_A1B8_0000F8707EB9__INCLUDED_)
