-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
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 OrientationMetadata
Metadata
Assignees
Labels
No labels