Introduce Enum Reflection
This MR is modeled after allpix-squared/allpix-squared!483 (merged)
This MR adds the Magic Enum class to allow for enum
reflection. An overload of corryvreckan::to_string_impl()
and corryvreckan::from_string_impl()
for enum
types enable parsing configuration keys directly into enums:
enum class FileType {
ROOT,
TXT,
CSV,
};
auto model = config.get<FileType>("file_type");
if(model == FileType::ROOT) {
// do sth
}
without odd string comparisons. If the requested key does not exist in the enum
, an error message with all available options is printed, emulating the behavior of the manual else
printouts used in string comparisons so far:
|23:08:27.240| (FATAL) [C:SomeModule:dut] Error in the configuration:
Could not convert value '"spock"' from key 'model' in section 'SomeModule' to type SomeModule::DepositionModel: invalid value, possible values are: mine, yours, theirs
The configuration needs to be updated. Cannot continue.