#ifndef EVENTS_H
#define EVENTS_H

#include "EventReceiverRecord.h"

namespace Salamander
{

class IEvent;

/*
** Public event manager class that is used by Salamander and the client application to pass events
** between modules. Register for events of a specific type by calling 'receive()'. Pass new events
** by calling 'send()'. Subclass 'IEvent' or any other event class to create user specific events.
*/
class Events
{
public:
	/*
	** Destructor.
	*/
    virtual ~Events();

	/*
	** Static access to the events class.
	*/
	static Events& events();

	/*
	** Use this method to send new events as they happen. Pass in an event of any type, and it
	** will be propogated to any receivers registered for that type.
	*/
	void send(const IEvent& event);

	/*
	** Call this method to register a function within a class as an event receiver. 'ReceiverType'
	** must be the classname of the receiver being passed in. The 'function' parameter must be a
	** pointer to the function within the receiver class, and must have parameters of 'void' and a
	** return type of 'void'. EventType is the type of event that is being registered for. Any 
	** subclasses of the event type will also be caught.
	*/
	template<class ReceiverType, class EventType>
	void receive(ReceiverType* receiver, void(ReceiverType::*function)(const EventType&));

protected:
	/*
	** This is a singleton and cannot be instantiated except by itself.
	*/
	Events();

	/*
	** We keep a linked list of EventReceiverRecords via their base class ReceiverRecord.
	*/
	ReceiverRecord* firstReceiverRecord_;
        
};

/*
** Events is a singleton and can be accessed via 'events()'
*/
static Events& events()
{
	return Events::events();
}

}

#include "Events.inl"

#endif // EVENTS_H
