enums

How can I wrap a Java enum and still iterate over it?

How can I have an abstract enum, or some kind of base enum? In my common code I'd like a notion of an enum placeholder, MyItems, without tying myself to a concrete enum. Then in each of my projects I would have a concrete implementation. E.g. Common Code public interface MyItems { // Marker interface } Project A public enum I...

Iterate through items in an enumeration in Delphi

I want to iterate through the items in an enumeration. I'd like to be able to say something like this: type TWeekdays = (wdMonday, wdTuesday, wdWednesday, wdThursday, wdFriday); ... elementCount := GetElementCount(TypeInfo(TWeekDays)); for i := 0 to elementCount - 1 do begin ShowMessage(GetEnumName(TypeInfo(TWeekdays),i)); end; ...

Using type aliases to Java enums

I would like to achieve something similar to how scala defines Map as both a predefined type and object. In Predef: type Map[A, +B] = collection.immutable.Map[A, B] val Map = collection.immutable.Map //object Map However, I'd like to do this using Java enums (from a shared library). So for example, I'd have some global alias: type Co...

C# Enum pointing to another Enum (refactoring)

Hi. Is there a way I could point an Enum to another Enum? Here are the needs and details: Currently: I have a two public classes com.abcd.MyManager and com.abcd.data.MyObject. MyObject class have pretty much everything is private except Types enum member. MyManager class uses MyObject class Notice MyObject class lives in a separate n...

Do .net FlagsAttribute enums need to be manually valued?

To allow for different formatting options on a method that displays a news story, I've created an enumeration that can be passed in to specify how it gets displayed. [Flags] private enum NewsStyle { Thumbnail = 0, Date = 1, Text = 2, Link = 4, All = 8 } string FormatNews( DataRow news, NewsStyle style ) { String...

Enumeration Utility Library

I'm looking for a open source library or examples for working with Enum types in .Net. In addition to the standard extensions that people use for Enums (TypeParse, etc.), I need a way to perform operations like returning the value of the Description attribute for a given enumeration value or to return a enumeration value that has a Desc...

Best way to store enum values in database - String or Int

Hello there, I have a number of enums in my application which are used as property type in some classes. What is the best way to store these values in database, as String or Int? FYI, I will also be mapping these attribute types using fluent Nhibernate. Sample code: public enum ReportOutputFormat { DOCX, PDF, HTML } pub...

Is it possible to create a generic bitwise enumeration 'IsOptionSet()' method?

The below code makes it easy to pass in a set HtmlParserOptions and then check against a single option to see if it's been selected. [Flags] public enum HtmlParserOptions { NotifyOpeningTags = 1, NotifyClosingTags = 2, NotifyText = 4, NotifyEmptyText = 8 } private bool IsOptionSet(HtmlParserOptions options, HtmlParserOp...

SQL query to get all values a enum can have

Postgresql got enum support some time ago. CREATE TYPE myenum AS ENUM ( 'value1', 'value2', ); How do I get all values specified in the enum with a query? ...

Java: Operations with Colors (add, subtract)? - Colors in a constant class

I'm working with java.awt.Color instances. Is there any way to do arithmetic operations on colors? Something like rgb(20, 20, 20) + rgb(10, 200, 170) = rgb(30, 220, 190)? What I'm trying to do: I have a gui that features a table, where if the user clicks on a cell, the other cells change color based on their relationship to the selected...

How to assign a value to an enum based on input from a file in C++?

I have a file with values like: START and STOP. I also have the following enum declared: enum Type { START, STOP }; I'm trying to set the enum equal to the first value in the file with something like this: enum Type foo; ifstream ifile; ifile.open("input.txt"); ifile >> foo; I'm getting the error: no match for ‘operator>>...

Template specialization for enum

Is it possible to specialize a templatized method for enums? Something like (the invalid code below): template <typename T> void f(T value); template <> void f<enum T>(T value); In the case it's not possible, then supposing I have specializations for a number of types, like int, unsigned int, long long, unsigned long long, etc, then...

How do I use an enum parameter in struts 2?

I'm trying to get an Action in Struts 2 to work with an Enum as an input parameter. What I've done so far looks like: public TestAction { public enum Module { VALUE1; } private Module module; public void setModule(Module module) { this.module = module; } public Module getModule() { return module; } } But wh...

C#: How to get the type definition of my enum..?

This feels like a really basic question, but I can't figure it out anyway.. How do I get the type of System.Windows.Visibility? I need to pass the type definition to a function. More precisly I'm writing unit tests for a IValueConverter I'm writing where the target type is a System.Windows.Visibility. What do I pass as target type when...

Enum flags in JavaScript

I need to emulate enum type in Javascript and approach seems pretty straight forward: var MyEnum = {Left = 1; Right = 2; Top = 4; Bottom = 8} Now, in C# I could combine those values like this: MyEnum left_right = MyEnum.Left | MyEnum.Right and then I can test if enum has certain value: if (left_right && MyEnum.Left == MyEnum.Left)...

Java Enums: List enumerated values from a Class<? extends Enum>

I've got the class object for an enum (I have a Class<? extends Enum>) and I need to get a list of the enumerated values represented by this enum. The values static function has what I need, but I'm not sure how to get access to it from the class object. ...

Is the use of previously defined members as part of later members in an enum definition legal?

namespace ValueType { enum Enum { Boolean = 0, Float = 1, Double, SInt = 8, SLong, UInt = SInt + (1 <<4), ULong = SLong + (1 << 4) }; } ...

Using enum types as properties in Objective C

I'm a veteran .NET developer making my first foray into Objective C programming. I'm having difficulty with a property of an enum type. Some context... I have an class header and enum like this: typedef enum { Open, Unavailable, Unknown } LocationStatus; @interface Location : NSObject { LocationStatus status; } @pr...

Is there C++ library to create strong Enums ?

Ideally I would like a following examples to work, but I guess some of it is not implementable in C++. { typedef StrongEnum<Red=0, Green=1, Blue=2> Color; // not a C++ syntax Color c = Color::Red; // static const Color d; //error: default constructor is private Color d = c; Color e = Color::OfInt(5); // ifdef DEBUG - Runti...

Is there a way to force cast int to enum when that int does not represent a valid enum value?

enum Answer : int { Yes = 1, No = 2 } Answer answer = (Answer)100; It throws, but I don't want it to. How? ...