Questions tagged [enum]

A data type consisting of a set of named values called elements, members or enumerators of the type.

Filter by
Sorted by
Tagged with
2
votes
0answers
103 views

Enum in PowerShell Class

I am playing with learning PowerShell classes, and I have a validation situation that kind of lends itself to Enums, as shown in the first example. With Enum ...
1
vote
1answer
55 views

Macro to generate an enum and an array of strings

Often when I find myself working with magic number enum values and I want to know what they represent, so I create an array of strings in order to print out their label. This macro automates that ...
6
votes
2answers
217 views

Coloring weekdays with enums

My aim is to assign a color to each workday in a week. So if a user enters a day as a str, then I can know which color it should have. Because colors and workdays ...
3
votes
2answers
90 views

Better approach on handling unexpected string upon converting it to the enum value

I have Grade enum and there is a static method to convert a string value to the particular enum value. ...
6
votes
2answers
104 views

Create a 2 way mapping to allow you to stringify enums or map one enum to another

I've created a class that creates key->value pairs but also value->key pairs - i.e. a reversible hash-map. This is because I want to be able to switch between corresponding members of 2 enums with ...
2
votes
1answer
50 views

Octave classdef enumeration workaround

AFAIK Octave still does not support enumerations, so I've done my best to write a workaround. The question is if there is something missing in code below, or maybe something can be improved? The ...
6
votes
2answers
79 views

Opposite access to enums

Consider I have many enums (Java) that looks somewhat like this: ...
2
votes
1answer
46 views

Cookie value to enum

Users can have a Cookie called lang that contains either the value "default=1" (English) or "default=2" (French). This cookie is used to determine their preferred ...
4
votes
1answer
100 views

Java enum-based factory to calculate entry parameters

I want to create a factory to return all Source instances that match given entry parameters- that is, I want to iterate through some Collection of objects and for each entry check boolean method. I ...
2
votes
1answer
32 views

Ranges of enum members that dwim

Inspired by this blogpost I decided to try and make it possible to have ranges of enum members that dwim, aka. that contain the actual members and not a stringified ...
5
votes
0answers
85 views

Reference enum values in Angular template without aliasing the enum type

Is there a way to improve this code? I'd like to use the enum type PaymentMethoddirectly in the angular template without renaming it to ...
2
votes
1answer
67 views

The most elegant way to locate two enums

I have situation where user has got options to select, and after selected any option will appear next options. For example : 1 - Add car 2 - Add motorcycle. 3 - Print cars 4 - Print motorcycles And ...
3
votes
1answer
490 views

overload c++ enum class operators and enable check value set

I use c++ 11 enum class usually instead of the old enums because many enums can contain the same value but as known they don't have the bitwise operators out of the box so we should define them ...
6
votes
1answer
82 views

Distinguish between different types of log items in a dictionary by their key

My logging adapter is using a dictionary for storing data that is passed from middleware to middleware. It is a one-liner: ...
10
votes
2answers
1k views

Bouncing map back into its bounds, after user dragged it out

Users like exploring maps, seeing all that is around. However they tend to go too far. To prevent the map from getting lost to the user it bounces back into the set bounds, as defined by a rectangle. ...
3
votes
0answers
87 views

Emulating a C++ enum class C++ in C

I am trying to emulate a C++ enum class in C and the code works as I expect. I used this code as indicated on Stack Overflow. ...
1
vote
1answer
67 views

Using enum for singleton implementations to choose way of doing something

I have this service that reads emails from a mailbox as they come and I want to extract its contents in a map structure. For now I am interested only in the actual email (no images or attachments). I ...
2
votes
1answer
45 views

Two ways to implement DND type abilities

I am creating a game in Java that uses the DND model for a lot of its components. I've hit a roadblock when it comes to creating and implementing abilities. I have ...
2
votes
0answers
36 views

Client wrapper for sending data to a downstream process

I am building a Python client for an alert process engine. The users can use this client to publish and clear the alerts. The client exposes two methods publish and clear to the users. These methods ...
10
votes
3answers
697 views

General purpose replacement for enum with FlagsAttribute

Enums with the FlagsAttribute have the disadvantage that you need to be careful when assigning their values. They are also inconvenient when you would like to allow ...
5
votes
1answer
115 views

Enum for handling network request errors in Swift

I'm working on a new API written in Swift 5 and I wanted to play with the new Result. I wanted to know what you guys think about this syntax: ...
3
votes
1answer
79 views

API for multiple printer attributes [closed]

I have network printers which have different attributes (e.g. supported network protocols, languages, status, print modes). ...
3
votes
1answer
183 views

Swift function to find a specific set of combinations of 3 digits within a larger integer array

I asked this question on Stack Overflow and was directed here. I'm working on a function that will help me quickly find all the upper structure triads (3-note chord) that I can add to a 4-note 7th ...
0
votes
0answers
113 views

Single chars mapped to enums in Rust

I'm writing a simple program to parse lines read from a file. As I'm new to Rust, I wonder if I'm creating too much boilerplate. A sample line in the file looks like this: ...
2
votes
2answers
732 views

Java Swing Exercise: BMI Calculator

This is my first question here and this is my working Body Mass Index Swing Calculator. Any improvement or recommendation is welcome. ...
6
votes
1answer
263 views

Get elementary values from a flagged enum

I created a little function that returns the elementary values from a flagged enum. By "elementary" I mean the values that are powers of 2, excluding any combined enum values. I was a bit surprised I ...
4
votes
1answer
105 views

Enum class for weight units

I have some enum classes for units, like Weight units (KG and LB). I am translating the code to Qt C++ from Java, and I'm wondering what the best way to do this is as enums cannot have constructors in ...
0
votes
1answer
180 views

Enhanced C# Enumeration / `enum`

I am developing my own kind of Enumeration like SmartEnum but trying to prevent the user to provide a recursive-ish type definition like below: ...
1
vote
1answer
75 views

Playing card class, written using enums

I wrote a card class a while back in this post here: Previous Question I know it has been a long time but I recently came back to the project and wrote it using an enum as suggested in the answer to ...
-1
votes
1answer
60 views

C++ API design - Should I pass enums as method parameters [closed]

I have two methods which are GetMinimumSize() and GetMaximumSize(). They return the maximum size of the window, and they take ...
3
votes
3answers
67 views

Simple boolean gate with two TriState inputs

As part of a code review I came across this isDummy(a,b)-Method and the question, whether it is more readable as a conjunction, or a disjunction: Original snippet: ...
2
votes
1answer
83 views

Image pixel-editing class with an enum for colors

I'm creating an image class that can be used by other classes to create visualizations of data. The class doesn't need to be complicated as the classes will be editing the images pixel by pixel. The ...
1
vote
1answer
43 views

Avoiding the use of ordinal() in an already-deployed enum

While reviewing a PR, I found an enum being used like this: ...
-1
votes
1answer
52 views

Adding additional attributes to an Enum object

I have used Enum objects before in PHP as shown here. However, I often find it's a requirement to have further attributes or metadata available on the instances. I came up with the example solution ...
2
votes
1answer
105 views

C++ class for a flag register in a Chip8 emulator

In order to learn C++ I decided to code a Chip8 emulator following a tutorial. When I came across the idea of a flag register and decided it would be fun to implement in order to get familiar with ...
1
vote
1answer
93 views

Using Enum in java to store a fixed set of mutable objects

I already posted this on Stack Overflow, but someone suggested to post it to Code Review instead. I am creating an Android app that draws to the canvas. For this, ...
0
votes
2answers
238 views

Factory method to create two kinds of cars based on an enum

I am implementing the factory method approach. My intention is to know if my approach is correct for factory method. Any modifications to be done to align with the approach? First I am creating an ...
2
votes
1answer
162 views

Manage Game Level with enum

Basically What I have is basket ball App. In which I have Added some levels and difficulties. logic is simply use tupple in enum and I have some methods to update / get current level with new values ...
2
votes
2answers
208 views

Creating an Enum with a Custom Type in Swift 4.x

I was in a code review today and someone said, "Why don't you do an enum on that?" I had started to, but conforming to a bunch of protocols seemed like a gigantic ...
4
votes
1answer
394 views

PHP class that behaves like enums

I'm relatively new to PHP and one of the things I miss from other languages are enums. After looking around for some samples on how can I have somewhat similar to them, I came up with this ...
9
votes
2answers
4k views

Int to Enum Extension Method

As you know, converting an int to an enum is straightforward. Doing it generically with type/range checking isn't. I looked for a reusable example since this seems like a common situation but did not ...
8
votes
3answers
297 views

Viable Flags (Enum) ValueObject

I was answering a question that led down a rabbit hole of creating an EnumValueObject with [Flags] capabilities. I started with ...
3
votes
1answer
676 views

I created a “enum string” container in c++

The reason I created this is because I wanted my string values to be type safe and I wanted to decrease the amount of bad data that has crept into my system due to hard coded values in the past. ...
5
votes
4answers
3k views

Python Constant Class, Different Enum Implementation

So I saw a need for and came up with a class implementation to group constants, which I'm calling a Constant Class. I wondered if there existed other similar implementations or if there is a flaw in ...
2
votes
2answers
669 views

Game Character class with many skills

Im creating a class that has all of my data in and can see it would quickly become messy. I feel that there must be a way of making it neater rather than making a new method each time For example. I ...
6
votes
2answers
2k views

Custom enumeration classes

Lately I've been using a lot of enums in my project and the lack of generic Enum constraint seems to be quite problematic. This combined with few other headaches ...
12
votes
1answer
167 views

Generic framework to handle parameterized commands

I asked this question a while ago, and this was one of the comments: There (mostly) seems to be a one-to-one mapping of a lot of your functions to IRC command verbs. For example, ...
1
vote
2answers
69 views

Advanced nuclides library

[Context] : I'm currently developing a program in nuclear physics and i would like to have a simple access to all nuclides. Technical specifications are : Since informations are static, I want them ...
1
vote
1answer
66 views

Nuclides enum library

I'm currently developing a program in nuclear physics and i would like to have a simple access to all nuclides. Technical specifications are : Since informations are static, I want them to be hard ...
2
votes
2answers
620 views

Simple barista application to calculate the price of a drink based on different ingredients

The scenario is that a customer orders a coffee from a vending machine by selecting a choice from several categories, such as size, flavor, and creamer type. Given their choices, we then have to ...

1
2 3 4 5