#pragma once

#include <iostream>
#include <memory.h>

#include "RTClock.hpp"


//From https://www.techiedelight.com/queue-implementation-cpp/
//and templated version https://www.techiedelight.com/queue-implementation-using-templates-cpp/


class FIFOQueue
{
public:
	struct FIFORecord		
	{
		uint8_t message[256];
		RTClock::CPFTimestamp timestamp;
	};
	
	FIFOQueue(uint16_t depth, uint16_t width, const std::string qID) : qDepth{depth}, qWidth{width}, qName(qID)
	{
		fifoRecords = new FIFORecord[qDepth];
		head = 0;
		tail = -1;
		count = 0;
		qName = qID;
	}		

	~FIFOQueue()      			   // destructor
	{
		//delete[] fifoRecords;
	}

	int32_t dequeue(RTClock::CPFTimestamp, uint8_t deQBytes[]);
	int32_t enqueue(RTClock::CPFTimestamp, uint8_t enQBytes[]);
	int32_t dequeue(FIFORecord &deQueueRecord);
	int32_t enqueue(FIFORecord enQueueRecord);
	int peek();
	int getCount();
	bool isEmpty();
	bool isFull();
	void clearRecord(FIFORecord &inRecord);
	void clearFIFO();

	uint16_t qWidth;
	
protected:
	const uint16_t qDepth;       // maximum capacity of the queue
	int32_t head;          	// points to front element in the queue (if any)
	int32_t tail;           // points to last element in the queue
	int32_t count;          // current size of the queue
	std::string qName;
	
	FIFORecord *fifoRecords;

private :
		
};



