473,473 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

enum with additional method

Hi,
I have an enum as
enum DitectionType{
X,Y,XD,YD
} ;
Now I want to wrap it with a class which returns orthogonal direction
for it. i.e X -Y , Y-X, XD-YD, YD->XD mapping should be there.
I can think of an static array which stores this mapping, and returns
the value based on index, rather than doing some if else.
Can anybody hint a good way to do it ( the primitive way is an global
static array of 4 element which can return the map like DirectionType
ortho[4] = {Y, X,YD,XD }; But I want a more descent and full proof
solution)

A second thing separately ,not for the above one, I want to make or or
some this enum. So instead of specifing an int, I need so specify a
set among those or / and values (may be using a set )
like I want X|Y to specify either X or Y direction, which should also
be a valid parameter type.
Thanks
abir

Feb 26 '07 #1
1 1790
toton wrote:
I have an enum as
enum DitectionType{
X,Y,XD,YD
} ;
Now I want to wrap it with a class which returns orthogonal direction
for it. i.e X -Y , Y-X, XD-YD, YD->XD mapping should be there.
I can think of an static array which stores this mapping, and returns
the value based on index, rather than doing some if else.
Can anybody hint a good way to do it ( the primitive way is an global
static array of 4 element which can return the map like DirectionType
ortho[4] = {Y, X,YD,XD }; But I want a more descent and full proof
solution)
The only fool proof solution is a switch statement. As soon as I change
the enumerator values in 'DirectionType', a simple lookup table is bust.

enum DirectionType { X=1,Y=7,XD=33,YD=42 };
A second thing separately ,not for the above one, I want to make or or
some this enum. So instead of specifing an int, I need so specify a
set among those or / and values (may be using a set )
like I want X|Y to specify either X or Y direction, which should also
be a valid parameter type.
Not sure I understand this one. Usually, for that you need the values
to be like bit masks, e.g. X==1, Y==2, XD==4, YD==8. The combination
of those is not necessarily going to be represented in your enumeration
by a named value, so you'll need to dance around a bit to massage the
combinations into that (static_cast helps).

Of course, a simple set of unsigned values (with names if you need them)
would probably work just as well.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 26 '07 #2

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

Similar topics

21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
6
by: | last post by:
I'm new to VS.NET, C#, and the enumerated datatype. I'm told that VS.NET 2005 Intellisense will pop up the members of an enum as a selection list if you are using the enum as a method parameter....
3
by: Arnold Schrijver | last post by:
I wrote a program that draws items to the screen and maintains a set of Offset values. There was a bug in the code, because objects were positioned wrongly. While debugging I found some peculiar...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
21
by: dllhell | last post by:
hi all, I have a problem with creating proc with a enum as a param. I wish to pass an enumeration in proc in which one I intend to do some operations with enumeration, but I don't know which one...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
0
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,...
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.