#include "Salamander.h"
#include "Events.h"

#include "EventReceiverRecord.h"
#include "FileIO.h"

namespace Salamander
{

Events::Events() :
	firstReceiverRecord_(NULL)
{

}

Events::~Events()
{
	// delete all event records
	while(firstReceiverRecord_)
	{
		ReceiverRecord* record = firstReceiverRecord_;
		firstReceiverRecord_ = record->nextReceiverRecord_;
		
		delete record;
	}
}

Events& Events::events()
{
    static Events events_;
	return events_;
}

void Events::send(const IEvent& event)
{
	// run through all the events, and fire ones of type IEvent
	ReceiverRecord* record = firstReceiverRecord_;
	while(record)
	{
		// send the event
		record->receiveIf(event);

		// linked list
		record = record->nextReceiverRecord_;
	}
}

}

