I have the source XML file that contains all the interface information.
One particular segement is the enum:
<enum name="InsId">
<enumerator name="kInsA" value="0"/>
<enumerator name="kInsB" value="1"/>
<enumerator name="kInsC" value="2"/>
<enumerator name="kNumIns" value="3"/>
</enum>
Passing this XML file throught he RTI generator creates a nice enum (not enum class, sadly).
typedef enum InsId
{
kInsA = 0,
kInsB = 1,
kInsC = 2,
kNumIns = 3
} InsId;
What I need is a way to convert some string representation to enum values. For example, if I have some configuration file saying that the `InsId` is "kInsA", then the code will set it to `InsId::kInsA`. I will have to create a local custom map to map strings to `InsId` values. If there are any changes in the XML file, the said map will have to be manually changed.
Is there any way to automate the creation of this map? For example some tool, already existing, that can process the XML file and output mapping from strings to enum values.
Thank you.
You can use the DynamicType/TypeCode (depending on which API you're using) to reflectively look up those names.
In modern C++ you would do something like this:
See dynamic_type and EnumType.
If you're using the traditional C++ API you can do something similar using InsId_get_typecode().
Great suggestion, thank you.