E
eXt
For a realtime-application (half an application at least, kind of a
framework) I am working with I need a event managing system and
naturally it must be fast. I have defined a set of available event
types in an enumeration like this:
enum Events {
EVENT_FOO,
EVENT_BAR,
EVENT_BAZ,
EVENT_CUSTOM1,
EVENT_CUSTOM2,
EVENT_CUSTOM3,
EVENT_MAX
};
I create an array of STL vector with EVENT_MAX elements. Any object in
the application can subscribe to an event by pushing itself onto the
events vector.
As seen in the enumeration above I have 3 custom events which will be
used to extend the application later (without changing the original
enumeration).
By defining a new enumeration I can rename the original names:
enum CustomEvents {
EVENT_CUSTOM_FOO = EVENT_CUSTOM1,
EVENT_CUSTOM_BAR,
EVENT_CUSTOM_BAZ
};
However, the prototype for subscribing and publishing events only
accepts the enumeration Events, for type-safe purposes. I could let it
take any integer but that would render the enumeration quite useless.
I don't know if I'm doing this all wrong but what I would like to do is
kind of extend the original enumeration with new names. Any
suggestions?
framework) I am working with I need a event managing system and
naturally it must be fast. I have defined a set of available event
types in an enumeration like this:
enum Events {
EVENT_FOO,
EVENT_BAR,
EVENT_BAZ,
EVENT_CUSTOM1,
EVENT_CUSTOM2,
EVENT_CUSTOM3,
EVENT_MAX
};
I create an array of STL vector with EVENT_MAX elements. Any object in
the application can subscribe to an event by pushing itself onto the
events vector.
As seen in the enumeration above I have 3 custom events which will be
used to extend the application later (without changing the original
enumeration).
By defining a new enumeration I can rename the original names:
enum CustomEvents {
EVENT_CUSTOM_FOO = EVENT_CUSTOM1,
EVENT_CUSTOM_BAR,
EVENT_CUSTOM_BAZ
};
However, the prototype for subscribing and publishing events only
accepts the enumeration Events, for type-safe purposes. I could let it
take any integer but that would render the enumeration quite useless.
I don't know if I'm doing this all wrong but what I would like to do is
kind of extend the original enumeration with new names. Any
suggestions?