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

	Delay.h													   JJS  1/30/96
	
		part of CONICAL, the Computational Neuroscience Class Library
	
	A Delay is a special type of Link: one that passes current via a time
	delay.  The VSource's voltage is buffered -- that is, stored in a
	queue -- so and reaches the other side of the link only after
	travelling through the queue.

	Since the queue must be updated with every tick, Delay inherits from
	Stepper as well, and must have its Step method called periodically.
	The "pQueSize" parameter to the Delay constructor determines how many
	Steps it takes information to travel through the queue.

	Requires:
		Link			-- base class
		Stepper			-- base class
		
**************************************************************************/

#ifndef DELAY_H
#define DELAY_H

#include "Link.h"
#include "Stepper.h"

class Delay : public Link, public Stepper
{
  public:
	Delay( VSource *pFrom, VSink *pTo, real pG=1, int pQueSize=1 )
	: Link( pFrom, pTo, pG ), itsQueSize(pQueSize), itsQueHead(0),
	  itsVQue(new double[pQueSize])
	{ for (int i=0; i<pQueSize; i++) itsVQue[i]=itsFrom->GetV(); }

	virtual void Step( const real dt ) {
		itsVQue[itsQueHead] = itsFrom->GetV();
		itsQueHead=(itsQueHead==itsQueSize-1 ? 0 : itsQueHead+1);  }

	virtual real GetE( void ) const { return itsVQue[itsQueHead]; }	// inspectors
	virtual real GetEG( void) const { return itsVQue[itsQueHead]*G; }
	
  protected:
  	double *itsVQue;		// stored voltages from VSource
 	int		itsQueSize;		// size of queue
  	int		itsQueHead;		// index of current voltage
};

#endif
