enums

Flag Enum and mutually exclusive Enum with overlapping meaning

I have a model that must be in one of the following mutually exclusive states: New, In Progress, or Closed. The application allows a user to save a record and then retrieve them by providing a list of matching states. I inherited an SQL database where the state is stored as an integer that represents bitwise flags. I have to call a pro...

How to display enum values in datagridview column

I have this Database, not of my design but I have to work with it, that contains a table like so : id | Name | status | ... -----+------------+----------+------ 1 | Product1 | 2 | ... 2 | Product2 | 2 | ... 3 | Product3 | 3 | ... ... | ... | ... | ... The status property re...

Export part of the namespace of a class

I have a class that includes an enum: class appearance{ // ... stuff ... enum color {BLUE, RED, GREEN}; }; I would like to attach part of the namespace (with using) so that I can refer to the value of the BLUE simply as BLUE, rather than appearance::BLUE. At the same time, I would like to keep the enum within the class{}, since I ...

Logic to find states in an Enum

I have a method that brings in an Enum value as an argument. enum { UITableViewCellStateDefaultMask = 0, UITableViewCellStateShowingEditControlMask = 1 << 0, UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1 }; There are four possible values: Only UITableViewCellStateDefaultMask is t...

enum ConsoleColor - is that type?

Hi, I know I can set property ForegroundColor of consele but what I am not sure is: the property is of the type enum or ConsoleColor, which is enum? I just do not know what I am exactly doing, setting the property to value of consolecolor (what is this, instance of enum? enum?). Thanks ...

Does it make a difference if I make an enum in a class static?

Basically, if I don't do all objects get a copy of all the enum values? ps: as always, references for your answer are always welcome... ...

How can I convert from a value to an enum?

I have an enum that looks a little bit like this: public enum Numbers { ONE(1), TWO(2), THREE(3); public final int num; public Numbers(int num) { this.num = num; } } I want to be able to convert from argument to enum, for instance from the int 1 to the enum ONE. Is there any built-in mechanism in Java Enums to do this, o...

Why could an enum type be used without defined

I am using VC2008 as my complier, and it is surprised to me that an enum could be used without defined: void func(enum EnumType type) { } Code above could be compiled and run without a problem, could anyone explain why it works? Update: I could define an empty enum in C++, as follow: enum EnumType {}; ...

Casting enum value to int when binding to dropdown using reflection

I have some code that binds an enumeration to a dropdown list, however, I'd like build the dropdown to take the integer value from the enum for the value and the description attribute for the text. I tried defining the kvPairList as a int/string and casting enumValue and an (int) I also tried converting.toInt32 Ideas? <select name=...

Is that possible and safe to add ENUM value to SQL database column type ?

I have an application that works with database (PHP + MySQL). One of the columns in the database table is of type ENUM('VALUE1','VALUE2'). Is that possible to add safely VALUE3 to the ENUM without damaging the data in the table ? ...

How to sort ENUM column in MySQL database ?

I have color column in MySQL table which type is ENUM('RED', 'YELLOW', 'MY_COLOR', 'BLACK'), and another name column which type is VARCHAR(30). I would like to get all table rows in the following order: YELLOW rows first, sorted by name RED rows last, sorted by name In the middle, all other rows, sorted by name Is that possible to m...

Implement enum in c# Interface and in one of interface's method signature

I have an interface Interface: interface IThing { Enum MyEnum {get;set;} string DoAction(MyEnum enumOptionChosen, string valueToPassIn); } Concrete implementation: public class Thing : IThing { public enum MyEnum { FirstOption, SecondOption, ThirdOption } string doAction(MyEnum enumOptionChosen, string value...

doubt in enum declaration

can i make my enum private or protected. for ex enum day{sun,mon,tue}; this is what we usually give. Can i give like private enum day{mon,..}; ...

How to combine templates with enums in C++?

There are a huge feature collection in C++ programming language that supply a strict control over datatypes. Frequently one would mold his code with template system to achieve the most adequate functionality while guaranteeing within it correct type preservation and flexibility in its manipulation. Less frequently enumerations are used f...

#define vs. enums for addressing peripherals

I have to program peripheral registers in an ARM9-based microcontroller. For instance, for the USART, I store the relevant memory addresses in an enum: enum USART { US_BASE = (int) 0xFFFC4000, US_BRGR = US_BASE + 0x16, //... }; Then, I use pointers in a function to initialize the registers: void init_usart (void) { v...

Is there a way to store "extensible enums" in an EnumMap?

I'm referring to the paradigm in Item 34 in Effective Java by Joshua Bloch.  I would like to take the method he's using which is to have each related enum implement a base interface, and initialize an EnumMap from the "sub-enums." See the code section below.  I'm getting a syntax error which I don't understand.  I'm not set on this meth...

What's the best C# pattern for implementing a hierarchy with an enum?

I'm implementing value types which represents a distance (or length). There's an enum that represents the different units of measure, eg: public enum DistanceUnit { Millimeter, Centimeter, Meter, Kilometer, Inch, Foot, Yard, Mile }; These measurements fall into one of two systems - either metric or imperial. ...

Java String enum

Hello, what is the best way to have a enum type represent a set of strings eg enum Strings{ STRING_ONE("ONE"), STRING_TWO("TWO") } so i can use them as Strings? Thanks ...

How to use typedef in dynamic properties?

It's the first time I'm trying to use typedef. Admittedly I don't have a very clear idea of what's going on but my understanding was that the values inside typedef get assigned integers starting with 0. I've tried to use them as integers but I get various warnings and errors. One of them is "[NSCFNumber objectForKey:]: unrecognized selec...

something like a using declaration for enums?

Basically this is what I'd like to do: struct A { enum E { X, Y, Z }; }; template <class T> struct B { using T::E; }; // basically "import" the A::E enum into B. std::cout << B<A>::X << std::endl; The reason why is that I want to basically inject the implementation details into my template class. At the same time...