/*
 *  CircBuffer.cpp
 *  BrainSim
 *
 *  Created by Joshua Hegie on 10/22/09.
 *  Copyright 2009 3544776. All rights reserved.
 *
 */

#include "CircBuffer.h"


Buffer::Buffer ( )
{
	head = 0;
	tail = 0;
}

Buffer::~Buffer ( )
{
}

bool Buffer::isEmpty ( ) const
{
	return (head == tail);
}

bool Buffer::isFull ( ) const
{
	return (tail == head+1);
}

void Buffer::insert (const SendItem &data)
{
	if (!isFull())
	{
		buff[head%maxSize] = data;

		head = (head+1)%maxSize;
	}
}

bool Buffer::remove (SendItem &ret)
{
	if (!isEmpty ())
	{
		unsigned int tmp = tail;

		tail = (tail+1)%maxSize;
		ret = buff[tmp];

		return true;
	}
	return false;
}