dynamic variable accesss...
Posted on 2005-04-12
I have no idea if this is possible, but I would think that it is (even if indirectly, such as by direct memory access, which would be less safe).
I code models for research groups. For every model there are a number of input parameters describing the input population that are read from a text file, but they're never all the same for all the models. I'd like to write a class that would take care of reading in the input variables (from the file) and setting the appropriate variables in the corresponding program to the input values. The tricky part is I'd like to be able to simply declare variables in the main program that are named the same as the ones in the input file and have the class I mentioned set those variables directly, but without having to change the class at all. Basically, to have the class dynamicall know which variables to set based on the read in names, just assuming that I have appropriately declared them in the main program (an error if they aren't declared is fine). Right now I read them into a map, setting the key to the variable name that I read in, and then manually set each variable value from the map value (since reading from the map is slow, and speed is the issue here, not memory). So I'd like to skip the manually setting part and have the class just "know" from the names that are read in. Is this possible? Is there any kind of low-level function to get a pointer to a variable based on a string name or something?