I'm using this lib to embed some resource files into an executable.
The resources can be accessed by the macro function LOAD_RESOURCE.
The resources I want to embed:
- resource/my_resource1.xml
- resource/my_resource2.xml
- resource/type1/my_resource3.xml
- resource/type1/my_resource4.xml
- resource/type2/my_resource3.xml
- resource/type2/my_resource4.xml
- ...
Loading the common resources is easy:
Resource res1 = LOAD_RESOURCE(resource_my_resource1_xml);
Resource res2 = LOAD_RESOURCE(resource_my_resource2_xml);
My problem is that I only know the type at runtime, so how can I load resources 3 and 4?
My current solution is through a switch case:
Resource res3, res4;
switch (type)
{
default:
case 1:
res3 = LOAD_RESOURCE(resource_type1_my_resource3_xml);
res4 = LOAD_RESOURCE(resource_type1_my_resource4_xml);
break;
case 2:
res3 = LOAD_RESOURCE(resource_type2_my_resource3_xml);
res4 = LOAD_RESOURCE(resource_type2_my_resource4_xml);
break;
}
However, this isn't very efficient nor pretty when I have N types and N resources for each.
Is there a better alternative? Can I somehow pass a string to the macro function as the argument? Something like LOAD_RESOURCE("resource_type" + type + "_my_resourceN_xml")?