As I started to rely more and more on enums, I quickly realized that I was starting to duplicate a lot of concepts.
For instance a character’s EProfession could be:
- Doctor
- Artist
- Politician
On the other hand a club EVIPAccess could be for:
- None
- Doctors
- Artists
- Politicians
- All
It started to feel a bit off that I had to create two distinct enums simply because I needed a “None” and an “All” concept. Moreover this was still limited as we might have to express that the VIP access is for both doctors and politicians, not artists.
I thought that using enums as bitmasks would be the perfect solution to this problem, nevertheless I was quickly disappointed when I realized that bitwise operations like (A & B == A) between the enum bytes and their bitmask form would not return the expected results.
After looking into the values it started to make sense. Bytes values were like this:
- Doctor = 0
- Artist = 1
- Politician = 2
While bitmasks values were like that:
- Doctor = 1
- Artist = 2
- Politician = 4
No wonder why the bitwise operations did not work. In an intent to not go back to my initial unsatisfying solution, I am turning to you guys to figure out if is possible to setup things in a way that allows to use enums as bytes in combination with their bitmask form. I think that would make my code both cleaner and more optimized.
Thanks.