-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMREX_ENUM: Add more capabilites (#4143)
Add support for `=`. For example, ```c++ AMREX_ENUM(MyColor, red, chi=red, green, blue, Default = green); ``` The underlying values are then ```c++ { red = 0, chi = 0, green = 1, blue = 2, Default = 1} ``` We can then have ```c++ assert(amrex::getEnum<MyColor2>("red") == MyColor2::red); assert(amrex::getEnum<MyColor2>("chi") == MyColor2::chi); assert(amrex::getEnum<MyColor2>("green") == MyColor2::green); assert(amrex::getEnum<MyColor2>("blue") == MyColor2::blue); assert(amrex::getEnum<MyColor2>("Default") == MyColor2::Default); ``` Because of there are duplicated values, using value to get name string will return the first matched string. Currently, I don't see a way to fix it. But, since `MyColor::red == MyColor::chi` is true, it's also not outrageously wrong. ```c++ assert(amrex::getEnumNameString(MyColor2::red) == "red"); assert(amrex::getEnumNameString(MyColor2::chi) == "red"); assert(amrex::getEnumNameString(MyColor2::green) == "green"); assert(amrex::getEnumNameString(MyColor2::blue) == "blue"); assert(amrex::getEnumNameString(MyColor2::Default) == "green"); ``` P.S. Chi means red in Chinese. https://en.wikipedia.org/wiki/Radical_155
- Loading branch information
1 parent
f547cb5
commit d572928
Showing
2 changed files
with
99 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters