enums

Most elegant way to morph this sequence

Hi folks: I've got the Day of the week stored in a database table (that I do not control), and I need to use it in my code. Problem is, I want to use the System.DayOfWeek enum for representation for this, and the sequences are not the same. In the database, it's as follows: 1 2 3 4 5 6 7 S M T W T F S I need it as follo...

Trying to get the associated value from an Enum at runtime in Java

I want to accomplish something like the following (my interest is in the toInt() method). Is there any native way to accomplish this? If not, how can I get the integer associated with an enum value (like in C#) ? enum Rate { VeryBad(1), Bad(2), Average(3), Good(4), Excellent(5); private int rate; private Rate(int rate) { this...

How to store an enum inside a DataColum of a DataTable and show localized text in .Net

I have to store on one DataColum of one DataTable an Enum containing some values. The enum is defined as follow: Imports System.ComponentModel Imports System.Globalization Public Enum FirmwareUpdateStatus <Description("updateNotExecuted")> UpdateNotExecuted = 0 <Description("updateSuccess")> UpdateSuccess = 1 <Description("...

Extending Java Enums

Here's what I am looking to accomplish, I have a class that has an enum of some values and I want to subclass that and add more values to the enum. This is a bad example, but: public class Digits { public enum Digit { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } } public class HexDigits extends Digits { public enum Digit { A, B, C, D, E, F...

Calling a C function in a DLL with enum parameters from Delphi

I have a third-party (Win32) DLL, written in C, that exposes the following interface: DLL_EXPORT typedef enum { DEVICE_PCI = 1, DEVICE_USB = 2 } DeviceType; DLL_EXPORT int DeviceStatus(DeviceType kind); I wish to call it from Delphi. How do I get access to the DeviceType constants in my Delphi code? Or, if I should just use the ...

Is there a way to serialize automatically enums as int?

Hello, Is there a way to serialize enums automatically as int? Every time I define a new enum and write std::stringstream stream; stream << myenum1; stream >> myenum2; the compiler complains that the operators << and >> are not defined. Do you know a way to tell the compiler to treat enums as plain int's? What makes the problem har...

C# Flag Enum delimiter

I have an Enum and member it type [Flags] public enum SearchFilter { types = 0x01, attributes = 0x02, methods = 0x04 } [System.Xml.Serialization.XmlAttribute("search-filter")] public SearchFilter search_filter = SearchFilter.types | SearchFilter.attributes | SearchFilter.methods; when serialize this class result attr...

Best method to store Enum in Database

What is the best method of storing an Enum in a Database using C# And Visual Studio and MySQL Data Connector. I am going to be creating a new project with over 100 Enums, and majority of them will have to be stored in the database. Creating converters for each one would be a long winded process therefore I'm wondering if visual studio o...

Help with enums in Java

Is it possible to have an enum change its value (from inside itself)? Maybe it's easier to understand what I mean with code: enum Rate { VeryBad(1), Bad(2), Average(3), Good(4), Excellent(5); private int rate; private Rate(int rate) { this.rate = rate; } public void increateRating() { ...

How to get C# Enum description from value?

I have an enum with Description attributes like this: public enum MyEnum { Name1 = 1, [Description("Here is another")] HereIsAnother = 2, [Description("Last one")] LastOne = 3 } I found this bit of code for retrieving the description based on an Enum public static string GetEnumDescription(Enum value) { FieldI...

C# underlying types of enums

What is the point of having enum SomeEnum : byte // <---- { SomeValue = 0x01, ... } when you have to make a cast just to assign it to the same type of variable as the enums underlying type? byte b = (byte)SomeEnum.SomeValue; ...

In Rails, how should I implement a Status field for a Tasks app - integer or enum?

For a Rails 3.0 Todo app, I have a Tasks model with a Status field. What's the best way to store the Status field data (field type) and still display a human-readable version in a view (HTML table)? Status can be: 0 = Normal 1 = Active 2 = Completed Right now I have this: Rails Schema Here: create_table "tasks", :force => true...

Enum values doubts?

Is there any possible way to do any arithmetic operations on enum values? enum Type{Zero=0,One,Two,Three,Four,Five,Six,Seven,Eight,Nine}; main() { enum Type Var = Zero; for(int i=0;i<10;i++) { switch(Var) { case Zero: /*do something*/ case One: /*Do so...

VB.NET Enumeration Representation

Is it guaranteed that the numeric values for an Enum with only uninitialized values start at zero and increment by one in the order defined? ...

Is there a better way to create a generic convert string to enum method or enum extension?

I have the following methods in an enum helper class (I have simplified it for the purpose of the question): static class EnumHelper { public enum EnumType1 : int { Unknown = 0, Yes = 1, No = 2 } public enum EnumType2 : int { Unknown = 0, Dog = 1, Cat = 2, Bird...

Converting an integer to a boxed enum type only known at runtime

Imagine we have an enum: enum Foo { A=1,B=2,C=3 } If the type is known at compile-time, a direct cast can be used to change between the enum-type and the underlying type (usually int): static int GetValue() { return 2; } ... Foo foo = (Foo)GetValue(); // becomes Foo.B And boxing this gives a box of type Foo: object o1 = foo; Conso...

C++ equivalent of Java Enum.valueOf()

Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java Enum.valueOf(string) on C++? ...

Why do I get an Enum constant reference cannot be qualified in a case label?

Why does the following code fail to compile, while changing the case statement to case ENUM1: doSomeStuff(); works? public enum EnumType { ENUM1, ENUM2, ENUM3; void doSomeStuff() { switch(this) { case EnumType.ENUM1: doSomeStuff(); } } } ...

Java Cascading Enums ?

Hello all, In my project, I have such class : class Statut { String satDomain; String staCode; } But working with Strings is not what I want. It is too permisive and using constants is not enough. I wanted to use enums but find a problem : class Statut { Domain satDomain; StatutCode staCode; } enum Domain { } enum S...

How to declare strings in enum in C

Hello, typedef enum testCaseId { "TC-HIW-0019" = 0, "TC-HIW-0020", "TC-HIW-0021" } testCaseId; I need my test cases to be represented in enum. In my test function, I need to switch between the test cases like: void testfunc(uint8_t no) { switch(no) { case 0: case 1: default: ...