Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • Corryvreckan Corryvreckan
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 39
    • Issues 39
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 14
    • Merge requests 14
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Issue
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CorryvreckanCorryvreckan
  • CorryvreckanCorryvreckan
  • Merge requests
  • !479

Introduce Enum Reflection

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Simon Spannagel requested to merge enum into master Nov 26, 2021
  • Overview 4
  • Commits 7
  • Pipelines 2
  • Changes 11

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.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: enum