enums

What is the difference between declaring an enum with and without 'typedef'?

The standard way of declaring an enum in C++ seems to be: enum <identifier> { <list_of_elements> }; However, I have already seen some declarations like: typedef enum { <list_of_elements> } <identifier>; What is the difference between them, if it exists? Which one is correct? ...

Is it bad practice to use an enum that maps to some seed data in a Database?

I have a table in my database called "OrderItemType" which has about 5 records for the different OrderItemTypes in my system. Each OrderItem contains an OrderItemType, and this gives me referential integrity. In my middletier code, I also have an enum which matches the values in this table so that I can have business logic for the diff...

MSVC enum debugging

Is there a quick way of outputting the names of enumerated values? I suppose you know what I mean, and at all this isn't possible as of course all of this data becomes irrelevant during compile process, but I'm using MSVC in debugging mode, so is it possible? ...

How can I store an inventory-like list of numbers?

I've got a list of number that I need to keep track of. The numbers are loosely related, but represent distinctly different items. I'd like to keep a list of the numbers but be able to refer to them by name so that I can call them and use them where needed easily. Kind of like an inventory listing, where the numbers all refer to a part I...

Has anyone got a copy of the Enumeration Parser class ("Stop the Madness")

Code from http://www.monstersgotmy.net/post/Enumerations-and-Strings-Stop-the-Madness!.aspx is mentioned in a number of questions about parsing Enums in C#. Has anyone got a copy of this code? The original site seems to have disappeared. ...

Pass enum value to method which is called by dynamic object

hello. I'm working on program which dynamically(in runtime) loads dlls. For an example: Microsoft.AnalysisServices.dll. In this dll we have this enum: namespace Microsoft.AnalysisServices { [Flags] public enum UpdateOptions { Default = 0, ExpandFull = 1, AlterDependents = 2, } } and we also h...

How to refer to enum constants in c# xml docs

I want to document the default value of an enum typed field: /// <summary> /// The default value is <see cref="Orientation.Horizontal" />. /// </summary> public Orientation BoxOrientation; The compiler warns that it couldn't resolve the reference. Prefixing F: or M: silences the compiler, but E: also does, so I'm unsure what prefix i...

Emacs enum indentation

I'm having a problem with Emacs's indentation of Java enums. While it indents the first member OK, it wants to give all of the rest of the static enum members an additional level of indentation. It looks like this: class MyClass { public enum MyEnum { ONE(1), //good TWO(2), // not good! THREE(3), ...

C#: Reflecting enum name

Let's say I have this class: public class SiteMapEntry { public static enum ChangeFrequency { Always, Hourly, Daily, Weekly, Monthly, Yearly, Never } } And this function: public class FooBar(SiteMapEntry.ChangeFrequency changeFreq) { } Which is called: string f...

Documenting using Sandcastle: Refering to enum value using <see>

I'm using Sandcastle 2.4.10520 and Sandcastle Help File Builder 1.8.0 to generate a .chm help file. In my documentation, I'm using <see> tags. If I try to refer an enum like <see cref="NumberStyles"/> it works perfectly. If I try to refer an enum value like <see cref="NumberStyles.AllowTrailingWhite"/> I get a link in the documentatio...

Map enum in JPA with fixed values ?

I'm looking for the different ways to map an enum using JPA. I especially want to set the integer value of each enum entry and to save only the integer value. @Entity @Table(name = "AUTHORITY_") public class Authority implements Serializable { public enum Right { READ(100), WRITE(200), EDITOR (300); private int value; ...

Loop through enumeration

What is best way to loop through an enumeration looking for a matching value? string match = "A"; enum Sample { A, B, C, D } foreach(...) { //should return Sample.A } ...

SFINAE failing with enum template parameter

Can someone explain the following behaviour (I'm using Visual Studio 2010). header: #pragma once #include <boost\utility\enable_if.hpp> using boost::enable_if_c; enum WeekDay {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY}; template<WeekDay DAY> typename enable_if_c< DAY==SUNDAY, bool >::type goToWork() {return fal...

Is there a a C-like way to get item number from enum in java ?

Perhap this is a simple basic question Having an enum public enum TK{ ID,GROUP,DATA,FAIL; } Can I get the order number for example ID=0, GROUP=2, DATA=3, FAIL=4 ? This is a way to to that, but a weird and long one! =S public enum TK{ ID(0),GROUP(1),DATA(2),FAIL(3); int num; TK(int n) ...

C#: are ranges possible with enums?

In C#, can you use number ranges in enum types, for example public enum BookType { Novel = 1, Journal = 2, Reference = 3, TextBook = 4 .. 10 } EDIT: The reason this is needed is to cast from a number to the enum type, eg: int iBook = 5 BookType btBook = (BookType)ibook Debug.Print "Book " + ibook + " is a " btBook a...

C#: do enums cast themselves as strings or integers as appropriate in the context

If I have the enum: public enum VehicleType { Car = 0, Boat = 1, Bike = 2, Spaceship = 3 } and I then do: int X = 10; VehicleType vt = (VehicleType)2; X = X + vt; Console.WriteLine("I travel in a " + vt + " with " + X + " people."); What should the output be in C#? ...

C#: can you add to an enum type in run-time

If I have the enum type: Public enum Sport { Tennis = 0; Football = 1; Squash = 2; Volleyball = 3; } Can I somehow add during run-time: PingPong = 4 ...

Get enum by its inner field

Hi! Have enum with inner fields, kind of map. Now I need to get enum by its inner field. Wrote this: package test; /** * Test enum to test enum =) */ public enum TestEnum { ONE(1), TWO(2), THREE(3); private int number; TestEnum(int number) { this.number = number; } public TestEnum findByKey(int...

value of enum members, when some members have user-defined values.

enum ABC{ A, B, C=5, D, E }; Are D and E guaranteed to be greater than 5 ? Are A and B guaranteed to be smaller than 5 (if possible)? edit: What would happen if i say C=1 ...

C# cast string to enum with enum attribute

Hello, i've got the following question: I've got public enum Als { [StringValue("Beantwoord")] Beantwoord = 0, [StringValue("Niet beantwoord")] NietBeantwoord = 1, [StringValue("Geselecteerd")] Geselecteerd = 2, [StringValue("Niet geselecteerd")] NietGeselecteerd = 3, } with public class Stri...