#ifndef EVENTRECEIVERRECORD_H
#define EVENTRECEIVERRECORD_H

#include "ReceiverRecord.h"

namespace Salamander
{

/*
** Receiver records hold information about the classes and functions that are expecting events to be passed to them. In
** order to send callbacks, the receiver class type and event type must be templated. However, we cannot store classes and
** functions of different types in a map, vector, or standard array.
**
** So, we use ReceiverRecord as a non-templated base class, stored in an internally-tracked linked list. Each EventReceiverRecord
** is a different subclass of ReceiverRecord, with the ability to callback the requesting function with the correct event. They
** can also be stored in a list due to the non-templated base class.
*/
template<class EventType, class ReceiverType>
class EventReceiverRecord : public ReceiverRecord
{
friend class Events;

public:
	/*
	** Destructor
	*/
	virtual ~EventReceiverRecord();

	/*
	** Call the receiver's callback method if the event is of the type we want to receive, or any subclass of that type.
	*/
	virtual void receiveIf(const IEvent& event);

private:
	/*
	** This type of class can only be used internally by the events system
	*/
	EventReceiverRecord();

	/*
	** 'function_' stores a pointer to a function in a class
	** of type 'ReceiverType', the instance of which is stored in 'receiver_'.
	** The function must an argument of void and a return type of void.
	*/
	typedef void(ReceiverType::*Function)(const EventType&);
	Function function_;
	ReceiverType* receiver_;
};

}

#include "EventReceiverRecord.inl"

#endif // EVENTRECEIVERRECORD_H
