enums

Persisting Enums in database tables

I have an order which has a status (which in code is an Enum). The question is how to persist this. I could: Persist the string in a field and then map back to enum on data retrieval. Persist this as an integer and then map back to enum on data retrieval. Create separate table for enum value and do a join on data retrieval. Thoughts...

C#: When using RegisterHotKey api call, why does it accept 1, 2, 4, and 8 as modifiers?

I reference to this post; http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html #region fields public static int MOD_ALT = 0x1; public static int MOD_CONTROL = 0x2; public static int MOD_SHIFT = 0x4; public static int MOD_WIN = 0x8; public static int WM_HOTKEY = 0x312; #endregion [DllImport("us...

Counting the number of flags set on an enumeration

I'm sure there must be a much better way of doing this. I'm trying to do a count operation on a Flags enum. Before I was itterating over all the possible values and counting the succesful AND operations. e.g. [Flags] public enum Skills { None = 0, Skill1 = 1, Skill2 = 2, Skill3 = 4, Skill4 = 8, Skill5 = 16, ...

Associating Additional Information with .NET Enum

My question is best illustrated with an example. Suppose I have the enum: public enum ArrowDirection { North, South, East, West } I want to associate the unit vector corresponding to each direction with that direction. For example I want something that will return (0, 1) for North, (-1, 0) for West, etc. I know in J...

Using an enum as a mapkey results in a RAW in the database

Hi, I'm trying to use an enum as a mapkey for a map in Hibernate, but Hibernate stores my enum as a RAW: I have this enum: public enum AccountType implements Serializable { CASH, CREDIT_CARD, GIRO, INVOICE, OTHER; } Which I'm trying to use as a key in a map: @CollectionOfElements @MapKey(columns = @Column(name=...

C++ enum not properly recognized by compiler

Can anyone explain why the following code does not compile (on g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-49))? struct X { public: enum State { A, B, C }; X(State s) {} }; int main() { X(X::A); } The message I get is: jjj.cpp: In function 'int main()': jjj.cpp:10: 'X X::A' is not a static member of 'struct X' jjj.cpp:10...

Bit operations on Enum

I'm having some problems with the following: I want to get the first visible AND frozen column of a column collection. I think this will do it: DataGridViewColumnCollection dgv = myDataGridView.Columns; dgv.GetFirstColumn( DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); Is it also possible to make a bi...

C# function that accepts an Enum item and returns the enum value (not the index)

say I have the following declarations: public enum Complexity { Low = 0, Normal = 1, Medium = 2, High = 3 } public enum Priority { Normal = 1, Medium = 2, High = 3, Urgent = 4 } and I want to code it so that I could get the enum value (not the index, like I earlier mentioned): //should store the value of the Complexity enum member ...

Arbitrary Java enum argument

I'm fairly new to java, and am used to enums essentially beeing nothing more than a named list of integers. Now I'm writing an implementation where a parent class has a couple of methods that take an enum value as argument. The enum will be defined in child classes, and will differ slightly. Since enums basically seem to behave like cl...

How to handle duplication between java enum and database table?

It is a quite common situation in our applications that some entity have to be represented by an enum: for example types, categories, status, and things like that. Often, there are conditions or flows in the code that use the values to decide between one action or another, so the values have to be "known" in some way for the applicatio...

Extending enums via user input

I have the below enum that I use for one of my filters and suit well to my object model public enum ColorGroups { White = 1, Brown = 2, Red = 3, Black = 4 } My concern is in the future when a client want to another color to the collection how do I extend the collection. I want the system to be fully dynamic and does no...

typedef enum, assiging a value within.

Hello, compiling with gcc C99 I have been using enums for a while now. However, I am using some sample code to develop my application. And I came across some code like this. I have been informed this is the best practice use when using enums. But I don't see how this has any advantages. typedef enum { TYPE_DATE, TYPE_TIME, ...

Java: Local Enums

Today, I found myself coding something like this ... public class LocalEnums { public LocalEnums() { } public void foo() { enum LocalEnum { A,B,C }; // .... // class LocalClass { } } } and I was kind of surprised when the compiler reported an error on the local enum: The member enum Lo...

What's the common practice for enums in Python?

What's the common practice for enums in Python? I.e. how are they replicated in Python? public enum Materials { Shaded, Shiny, Transparent, Matte } ...

Using Spring IoC to set up enum values

Hi there, Given the followin enum : public enum Car { NANO ("Very Cheap", "India"), MERCEDES ("Expensive", "Germany"), FERRARI ("Very Expensive", "Italy"); public final String cost; public final String madeIn; Car(String cost, String madeIn) { this.cost= cost; ...

Number of elements in an enum

In C, is there a nice way to track the number of elements in an enum? I've seen enum blah { FIRST, SECOND, THIRD, LAST }; But this only works if the items are sequential and start at zero. ...

how to access a mySQL enum field with Java ResultSet and PreparedStatement

Quick question what's the correct way to use ResultSet and PreparedStatement to access an ENUM field in MySQL? ...

dynamic enum in C#

How do I create a dynamic enum (and subsequently use the enum choices) in C# based on values in a database lookup table? (using enterprise library data layer) e.g. If I add a new lookup value in the database, I don't want to have to add the extra static enum value declaration in code. Is there such a thing as this? I don't want to creat...

Java Enums can have behavior?

In Java, an Enum can do the great things that Enums do, but can also have methods (behavior and logic). What advantage does that have over using a class using an enum? Simple examples to illustrate the point would also be welcome. ...

String to Enum

Is there a way to associate a string from a text file with an enum value? The problem is, I have a few enum values stored as string in a text file which I read on the fly on meeting some condition... Now I want to assign the read value to an enum. What is the most effective way to do so? It needn't be the simplest approach. ...