Skip to content

[Feature Request] Add automatic enum parsing in configuration files #18

@jim-bcom

Description

@jim-bcom

According to the documentation, currently supported types for properties are:

[int, uint, long, ulong, string, wstring, float, double, structure]

I don't know if this is possible, but it would be nice to be able to handle enum types, so that all the required checks are performed by XPCF instead of doing this kind of things in every components:

  • Get the enum value as a string in the configuration file
  • Maintain an associative container / add a method that performs a switch to map the string value to the enum value and check the input string is among the valid values of the enum.

Maybe something like this MIT-licensed library could be used ?
https://github.com/Neargye/magic_enum

It can get the enum value out of a string

std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
  // color.value() -> Color::GREEN
}

With XPCF, a component declaring a property could then look like this

enum class Orientation { Up, Down};
...
Orientation m_orientation;
...
declareProperty<Orientation>("orientation", m_orientation); // raises a configuration error if the string value cannot be converted to an Orientation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions