473,837 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_FO O = EVENT_CUSTOM1,
EVENT_CUSTOM_BA R,
EVENT_CUSTOM_BA Z
};

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 2713
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_FO O = EVENT_CUSTOM1,
EVENT_CUSTOM_BA R,
EVENT_CUSTOM_BA Z
};

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_FO O = EVENT_CUSTOM1,
EVENT_CUSTOM_BA R,
EVENT_CUSTOM_BA Z

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_FO O = EVENT_CUSTOM1;
static const Events EVENT_CUSTOM_BA R = EVENT_CUSTOM2;
static const Events EVENT_CUSTOM_BA Z = 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
12634
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 value="red"/> <xsd:enumeration value="yellow"/> <xsd:enumeration value="blue"/> </xsd:simpleType>
8
6516
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" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
2
1817
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 Home 2 Business 3 Cell Now, I could associated each enumeration value with the phone_cd used in the
2
2220
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
5665
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" for a second if you don't mind). However, it existed within intuitive language semantics, whereas the new "yield" keyword, while highly convenient, is also one of the most gross warping of language concepts to date... public IEnumerator...
1
5040
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"/> <xsd:enumeration value="CDAUDIO"/> <xsd:enumeration value="DVD"/> <xsd:enumeration value=""/><!-- can be an empty string --> </xsd:restriction>
3
2549
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"> <xs:enumeration value="Mon"/> <xs:enumeration value="Tue"/> <xs:enumeration value="Wed"/>
0
500
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
1711
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 reason.Who can give me some advise!?
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9685
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10886
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10580
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9413
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7817
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.