enums

.NET Dynamic Objects with Reflection

How do I determine if a Nullable(of Enum) is indeed an Enum by means of reflection? I'm working with a method that dynamically populates an object of type T with an IDataReader retrieved from a database call. At its essence, it loops through the datareader's ordinals, and all the properties of T and populates the properties that match ...

What is the best way to use JavaDoc to document a Java enum?

I've just started using Java's enums in my own projects (I have to use JDK 1.4 at work) and I am confused as to the best practice of using JavaDoc for an enum. I have found that this method works, but the resultant code is a little unrefined: /** * Doc for enum */ public enum Something { /** * First thing */ FIRST_THING, /** * Second t...

How should C bitflag enumerations be translated into C++?

C++ is mostly a superset of C, but not always. In particular, while enumeration values in both C and C++ implicitly convert into int, the reverse isn't true: only in C do ints convert back into enumeration values. Thus, bitflags defined via enumeration declarations don't work correctly. Hence, this is OK in C, but not in C++: typedef en...

Is there a simple script to convert C++ enum to string?

Suppose we have some named enums: enum MyEnum { FOO, BAR = 0x50 }; What I googled for is a script (any language) that scans all the headers in my project and generates a header with one function per enum. char* enum_to_string(MyEnum t); And a implementation with something like this: char* enum_to_string(MyEnum t){ ...

Getting the max value of an enum

How do you get the max value of an enum? ...

How to use enums in Oracle?

How do you use enums in Oracle using SQL only? (No PSQL) In MySQL you can do: CREATE TABLE sizes ( name ENUM('small', 'medium', 'large') ); What would be a similar way to do this in Oracle? ...

How to easily map c++ enums to strings

I have a bunch of enum types in some library header files that I'm using, and I want to have a way of converting enum values to user strings - and vice-versa. RTTI won't do it for me, because the 'user strings' need to be a bit more readable than the enumerations. A brute force solution would be a bunch of functions like this, but I f...

Are C# enums typesafe?

Are C# enums typesafe? If not what are the implications? ...

java Enum definition

Hi, I thought I understood Java generics pretty well, but then I came across the following in java.lang Class Enum<E extends Enum<E>> Could someone explain how to interpret this type parameter? Bonus points for providing other examples of where a similar type parameter could be used. Cheers, Don. ...

Where is the best place to locate enum types?

I have found that there is generally a singe type or namespace that takes in any particular enum as a parameter and as a result I have always defined those enums there. Recently though, I had a co-worker make a big deal about how that was a stupid thing to do, and you should always have an enum namespace at the root of your project where...

Pros and cons of using nested C++ classes and enumerations?

What are the pros and cons of using nested public C++ classes and enumerations? For example, suppose you have a class called printer, and this class also stores information on output trays, you could have: class printer { public: std::string name_; enum TYPE { TYPE_LOCAL, TYPE_NETWORK, }; class out...

Which Typesafe Enum in C++ Are You Using?

It is common knowledge that built-in enums in C++ are not typesafe. I was wondering which classes implementing typesafe enums are used out there... I myself use the following "bicycle", but it is somewhat verbose and limited: typesafeenum.h: struct TypesafeEnum { // Construction: public: TypesafeEnum(): id (next_id++), name("") {} ...

JAXB - XJC - influencing generated typesafe enum class and members

Hi there, When compiling the following simpleType with the XJC compile (from the JAXB package)... <xs:simpleType name="test"> <xs:annotation> <xs:appinfo> <jaxb:typesafeEnumClass/> </xs:appinfo> </xs:annotation> <xs:restriction base="xs:string"> <xs:enumeration value="4"> <xs:annota...

How should I implement a dropdown box which contains a list of items which need to be shown in different languages?

I'm trying to design a form which contains a dropdown box containing a list of grocery item choices. What criteria should I look at when trying to decide on whether to use a java enum or a lookup table? Also, I will need to plan ahead for i18n support for the dropdown strings. ...

Java extendable enumeration

Is there a way to write an enumeration that can be extended. I have several methods that I would like to alway have available for my enumerations. For example I use an enumeration for my database fields. I include the actual field name in the database. public enum ORDERFIELDS { OrderID("Order_ID"); private String...

Exposing an enum from a library class

In C#, I am using a library that defines an enum. I would like to allow consumers of my code (in a different assembly) to pass in an enum value as a parameter to one of my functions without having to reference the underlying library themselves. Is there a way for me to expose the library's enumeration to my consumers? ...

How do I cleanly extract MySQL enum values in Perl?

I have some code which needs to ensure some data is in a mysql enum prior to insertion in the database. The cleanest way I've found of doing this is the following code: sub enum_values { my ( $self, $schema, $table, $column ) = @_; # don't eval to let the error bubble up my $columns = $schema->storage->dbh->selectrow_hashr...

Ways to save enums in database

Hey guys. I am wondering what the best ways to save enums into a database is. I know there are name() and valueOf() methods to make it into a String back. But are there any other (flexible) options to store these values? Is there a smart way to make them into unique numbers (ordinal() is not safe to use)? Any comments and suggestions...

What does '^' do in c# (Enums)?

I was reading some 3rd party code and I found this: x.Flags = x.Flags ^ Flags.Hidden; What does it do? I've used '&' and '|' for bitwise 'and' and 'or' with enums, but it's the first time I see the that symbol... ...

How to convert string result of enum with overridden toString() back to enum?

Given the following java enum: public enum AgeRange { A18TO23 { public String toString() { return "18 - 23"; } }, A24TO29 { public String toString() { return "24 - 29"; } }, A30TO35 { public String toString() { return "30 - 35"; } }, } Is th...