Problem: In my system there are a lot of statistic calculators wrapped as classes. My job is to combine the values from these calculators into one single value called 'total'.
The 'model' that explains how these calculators should be combined is given as a table --- either a csv file or a table in MySQL
instance_name,accessor,argument,post_processing_function_name
fleet_statistics,getCash,2017,func1
city_statistics,getPopulation,2016,func2
....
....
My current solution: I wrote a python script to read the csv file and generate c++ code like this:
double computeTotal()
{
double total = 0;
total += func1(fleet_statistics->getCash(2017));
total += func2(city_statistics->getPopulation(2016));
....
....
}
Using python to generate the code is very convenient, but the problem is that, it is no longer a 'pure' c++ program. I need to hack the makefile to make sure that the generated c++ file is up to date.
A more elegant solution is to use meta-programming to generate the code in c++ using c++ rather than python. Can anyone show me how to do this?
Jut to mention a few points:
the CSV file is generated for by some business-logics-related-scripts. It has a couple thousands of rows. It is impossible to write the c++ code manually.
The CSV file can change every time when we make a new release.
I use CSV format as an example. It could be a table in MySQL if that will make things easier
objects in the instance_name column are not necessarily from the same BaseClass. The accessor's function signature is variant as well. So it is not convenient to use a function pointer
Thanks!