#include "Salamander.h"
#include "Stream.h"

namespace Salamander
{

Stream::Stream(const UniqueId& typeId) :
	typeId_(typeId),
	streamDatas_(NULL)
{
	
}

Stream::~Stream()
{
	// Clean up memory
	while(streamDatas_.size())
	{
		const IStreamData* streamData = streamDatas_.back();
		streamDatas_.pop_back();
		delete streamData;
		streamData = NULL;
	}
}

const UniqueId& Stream::typeId()
{
	return typeId_;
}

const IStreamData& Stream::get(unsigned int index) const
{
	// TODO : how do we handle out of bounds case?
	//if(index >= streamDatas_.size())
	//	return NULL;	

	return *streamDatas_[index];
}

bool Stream::add(const IStreamData& streamData)
{
	// The type of stream data must remain consistent.
	if(streamData.typeId() != typeId_)
		return false;

	streamDatas_.push_back(&streamData);
	return true;
}

bool Stream::set(unsigned int index, const IStreamData& streamData)
{
	// Stream data must remain the same type when we set it.
	if(streamData.typeId() != typeId_ ||
	// Can't modify stuff that doesn't exist
	   index >= streamDatas_.size())
		return false;

	streamDatas_[index] = &streamData;
	return true;
}

unsigned int Stream::size() const
{
	// expose the vector's method.
	return streamDatas_.size();
}



}
