A data type consisting of a set of named values called elements, members or enumerators of the type.
6
votes
4answers
255 views
An enum that has situationally invalid entries
Is it considered bad style to have that BOTH value in the Direction enum? Problems can arise from ...
3
votes
1answer
39 views
An attempt to extend an enum to prevent branching without violating the Open-Closed principle
I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, ...
6
votes
1answer
89 views
Smart enum templates
Here is some code I wrote 10 years ago. I'm now reviewing it and there are a lot of things I don't like.
There is possibility for weird behaviour if the template is attempted to be used with a type ...
12
votes
4answers
431 views
Enum with getting subset
I just wrote this but I'm not sure if this is good practice. Can someone give me advice as to whether it's good or how I can do better or even it's bad code?
The point is that I need a sub ...
4
votes
1answer
55 views
“Agenda” test application for Enum
I'm still new in Java so I always try to find new ways and improve my skills.
I found enum in Java to be very powerful (maybe excessively?) and while I was reading ...
5
votes
1answer
56 views
Turn multiple key presses into single GameAction
The InputHandler class for my game detects key presses, turns each one into a GameAction, and raises an event.
...
12
votes
5answers
822 views
Java enum containing a hash map for look up
I have the below enum. I need to get the description by code. It is working but can it be improved still?
...
7
votes
4answers
221 views
Saving enum value using name()
Let's assume I have an enum type
enum ComponentState {
TURNED_OFF,
TURNED_ON,
SUSPENDED,
TO_REPAIR;
}
This enum describes a state of some ...
4
votes
1answer
106 views
Enumerating a boolean in C
This is one way to make a boolean in C.
typedef enum {
false = 1 == 0,
true = 0 == 0
} bool;
Recently I made some like
...
7
votes
2answers
72 views
Is there a better way to insert an enum into a set without macros?
I created an enum for a class and in the constructor I inserted all the enum values into a set. I am wondering if there is a ...
4
votes
1answer
862 views
Concerned with Enums, JSON, and ASP.NET MVC
I am writing an application that uses ASP.NET MVC for its front end, and for the back end, it uses RavenDB to store data. This ...
3
votes
1answer
76 views
Converting data when output std container via ostream_iterator
I have a strongly typed enum and std::vector of this type.
...
3
votes
1answer
102 views
Genericizing PropertyValues
This should be the last iteration for this code.
Question 1
Does this approach make sense or am I heading down the wrong path?
Question 2
The only thing I can see to make this better is to ...
2
votes
1answer
95 views
Automatic C++ enum to string mapping macro
I have long been looking for an elegant, one-line solution to map enum to strings automatically, for use with the << and ...
9
votes
5answers
615 views
3
votes
2answers
228 views
2
votes
1answer
132 views
User-defined color implementation in windows console
I have implemented an user defined colors enumerator, and if is possible I appreciate if I will get a code review.
I want to know if my implementation is correctly or must improve it.
If there exist a ...
5
votes
1answer
63 views
One-line initialisation for a constant list with all entries except one from another list
I'm looking to simplify the initialisation of the second constant, preferably to just one line. Any ideas? Anything from Guava or JDK (up to 1.6) is ok to use.
...
5
votes
3answers
3k views
Loading a combobox with an enum and binding to it
I have the following code to load an enumeration into a bound combo box, but am not quite happy with it.
I would prefer to store the actual enum value in the ...
6
votes
1answer
601 views
Variadic macro enum class “reflection” in C++11
I recently had the need of "reflecting" multiple enum class constructs in order to get their elements' names as std::string ...
5
votes
1answer
126 views
Critique of Cardinal Direction Enum
I'm working on a simple game in which I need to track the cardinal direction of an object. I experimented with using the enum's ordinal value, as well as using switches for the rotation, but both ...
2
votes
4answers
179 views
Enum or Constant
I'm writing a SDK for a NFC device in .NET so I don't have to import the SDK from C++. Right now I'm working on the ISO14443-3 part which is just simple Halt, Request, and Anticollision commands. The ...
4
votes
0answers
175 views
Building a good C++11 template library - compile-time checked enum array
The task is to add data or values to members of a given enum class. The compiler should check, if a value for each enum member is available, and not just default construct empty values. It is a tool ...
4
votes
2answers
340 views
Alternative to starting enum values with a number?
I have an enum like the following:
enum MeasurementBandwidth
{
Hz1 = 1,
Hz3 = 3,
Hz10 = 10,
...
}
But I do not like the ...
3
votes
2answers
109 views
3
votes
1answer
70 views
Critique of enum
I'm working my way through The Java Programming Language, Fourth Edition - The Java Series. This is Exercise 6.4:
Expand your traffic light color enum from Exercise 6.1 on page 152 so that each ...
7
votes
4answers
400 views
Tic-Tac-Toe design
Kindly look at this code and point out design flaws or areas for improvement. I think I've done the last part right (the enum). I think the rest of the design is flawed but I am very new to ...
3
votes
3answers
4k views
Converting enum values to strings in C++
Question 1: functionxxx_as_string() is used below. How else could it be more elegantly named?
Question 2: Is the static char* array method adopted below the only solution? Best solution? Any ...
1
vote
0answers
413 views
“options” binding with an enum as data source
I need to bind a dropdown to an enum. For this I've made a key/value class and manually go through each enum option to add it. Is there a more elegant way?
Note: I'm not looking for naming guidelines
...
0
votes
3answers
684 views
Converting a c# enum into a list to be sent to the client
I want to use the enum on the client for a dropdown list. Does this make sense, or is there a smarter way of doing this?
...
2
votes
3answers
174 views
An attempt at a simple type safe python enum
There have been many posts here about enums in python, but none seem to be both type safe and simple. Here is my attempt at it. Please let me know if you see anything obviously wrong with it.
...
3
votes
1answer
147 views
Enums with different methods, useful or abuse?
I'm wondering if the way I wrote our TextHelper class is a really a proper way to do it.
We have products that are interlinked in different ways and every product has multiple text fields that might ...
1
vote
1answer
72 views
Is this enum declaration “wrong,” or is it just me?
Legacy code has this enum declaration:
public enum ChangeListTypes
{
Always = 1,
Never = 2,
CostChange = 3,
None = 0
}
I would have done it this ...
38
votes
15answers
2k views
Cleaner way to code BOOL×BOOL→ENUM mapping?
Does this part look clean enough? Any suggestions on how to make it cleaner?
...
4
votes
1answer
241 views
Parse Flags enum from array of booleans
I need to get from an array of booleans to a Flags enum.
Here's what my enum looks like:
...
11
votes
2answers
625 views
Advice on naming convention with enum
I have an enum called NodeType. Since my public field does not want to conflict with enum, ...
1
vote
1answer
1k views
Class to simulate enums in PHP
I have been reading this thread on Stack Overflow about simulating enums in PHP and it seems that the most common approach is to use class constants. My problem with that is I can't use it for type ...
2
votes
2answers
2k views
How can an Enumeration with Descriptions be cast into a Dictionary?
The Enumeration in question is based on int, so the following Extension returns a Dictionary<int, string> of the Enum's ...
18
votes
5answers
2k views
Boolean enums: improved clarity or just overkill?
Suppose we are writing a GUI toolkit in C++ (though this question may also apply to other languages). We have a button class with a member function hide, which ...
3
votes
2answers
2k views
Boolean flags encoded as integer implemented with EnumSet
I'm a beginner in Java so I would appreciate a review of following simple class - in fact it's my first real usage of enums.
The background: I'm parsing MySQL internal client-server protocol. One of ...
5
votes
3answers
180 views
Should I design my enumeration in some way that indicates what the highest value is?
This is a subtle question about design in which I want to find the most elegant and appropriate solution.
I have an enumeration representing a French card deck (see code below). With it I need to do ...
6
votes
3answers
3k views
Enum vs int wrapper struct
I am writing code that has objects having integer member variables where the integer value has a specific constant meaning, which normally means "use an enum".
Suppose the values are the days of the ...
2
votes
1answer
186 views
10
votes
1answer
11k views
Getting the value of a custom attribute from an enum
Suppose we have an enum called "Planet" and it has a custom attribute of class "PlanetAttr",
these methods will give you the attribute value for a given Planet value:
...
8
votes
1answer
181 views
RubyGem for Enums
A little background first. I've been working on a fairly large Rails application which quickly grew into a breeding ground for "smelly" code. One antipattern we were using a lot was storing objects ...