class Event
{
public:
Event(int eventId)
:
m_eventId(eventId)
{
}
private:
int m_eventId;
}
When users write events they do it like this:
enum
{
kCustomEvent = 'cste'
}
class CustomEvent
{
CustomEvent()
:
Event(kCustomEvent)
{
}
}
This is an idea I got from using the C4 Engine.. Its efficient to use integers like this, but Its dangerous as events might be called the same using the four letter char.. I could use strings, but hashing and comparing them wouldn't be as efficient..
I'm guessing your building your own engine/library intended for other people to use? Either way, my most personal opinion is that you can't protect another programmer from every silly mistake he or she might do. If it's documented that you should use enum values and someone attempts to use [font=courier new,courier,monospace]'4'[/font] it should simply fail, preferably with an error message telling that programmer to read the .. manual.
If you actually try to protect someone from every possible error you'll realize that you can never do that good enough. What if one programmer uses the string 'cast' hoping that you'll provide typecasting while another programmer uses the same string 'cast' hoping that his or hers character will throw a fireball?
Summary: Use integers if only one option is available; if there's several options (flags) available you could use bitmasks. Make sure to document it.
Those who can do, do; those who can't do, do teach.
then you could use it like:
struct superEvent : Event_<superEvent>
{
};
Event* e = new superEvent();
if (superEvent.checkType(e))
{
//yes this is the event i am looking for
}
//or
superEvent* event = superEvent.convert(e);
if (event)
{
//yes this is the event i am looking for
}