473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Extend an enumeration

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?

Oct 26 '06 #1
3 2690
eXt wrote:
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?
Add a function overload that accepts your custom event type and
converts it to the generic event type. Should be nothing but a switch
statement (or perhaps a std::map lookup depending on how many there
are).

Cheers! --M

Oct 26 '06 #2
eXt

mlimber wrote:
Add a function overload that accepts your custom event type and
converts it to the generic event type. Should be nothing but a switch
statement (or perhaps a std::map lookup depending on how many there
are).
I guess that would work, just too bad the one using custom events has
to do that part. I guess that's the price to pay.

Oct 26 '06 #3
eXt wrote:
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?
Use this instead:

static const Events EVENT_CUSTOM_FOO = EVENT_CUSTOM1;
static const Events EVENT_CUSTOM_BAR = EVENT_CUSTOM2;
static const Events EVENT_CUSTOM_BAZ = EVENT_CUSTOM3;
Regards,
Bart.

Oct 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
2
by: centrino | last post by:
hi, I want to extend System.Net.Sockets.ProtocolType to IPinIP protocol, how can i do that. Do i have to make new class or enum stuct for this type ? regards
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
1
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/>...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
2
by: jidixuelang | last post by:
As I know,it's not well to extend Object.prototype derictly. In the Prototype(JS Framewoke),there is no extend Object.prototype. It only add some static method for Object class. I want to konw the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.