I will try to describe the context of the problem a bit, and then some observations. I do not have a specific question; I am just looking for advice, primarily.
I have a number of .h files which correspond to test/demos for the user. Each .h file defines one class corresponding to one test/demo. It should be noted that all these classes inherit from a common base.
In my main file, I need to #include all these .h files and identify each of their classes. Then, for n classes, there will be n buttons. Each button, when pressed, creates a new instance of the class it corresponds to. When released, it deletes it. The buttons cannot have their own instantiation stored; they must be created and deleted when pressed and released; it is imperative that that no two instances of different classes be instantiated at the same time.
This raises a few issues (and to clarify the context):
- All of the information about a particular test/demo should be in the same place (i.e., the test’s name, the test’s filename, and the test’s class name should all be in the same area of the code. Preferably the same line. This is just good design.
- A key piece of information of the class is its C++ name. Unfortunately, as far as I know, such tokens can only be written into code that instantiates it (so it cannot, for instance, be stored in a struct containing information about each test/demo; I tried templates, but then it was a list of templates whose arguments all differed).
Point 1 and point 2 led me to make a macro expression of the following form:
#define TESTDEMO_DATA(MACRO)\
MACRO("<name 1 here>",class1_symbol,"<filename 1 here>")\
MACRO("<name 2 here>",class2_symbol,"<filename 2 here>")\
MACRO("<name 3 here>",class3_symbol,"<filename 3 here>")\
...
From here, I could very simply create buttons (I used TESTDEMO_DATA to generate functions that would create instances of classn_symbol, and then just had each button call the right one).
But now I am stuck: I clearly cannot write a macro that to pass to TESTDEMO_DATA that will #include just the filename, as I might like, because that would require a multipass preprocessor. I don’t want to write the #includes separately either, because that violates point 1, though it’s the best I can think of right now.
Ideas?
Generate code from a script.