I have a piece of code that applies a lot of computations to a set of data. This data is organized in a class, and consists mostly of scalars and arrays of floats and doubles. The problem is that the variables on the class depends on the input file structure, i.e., file A may have 10 scalar variables and B may have 20 arrays. How can I create an abstraction to deal with this heterogeneous data?
I thought of creating a class Data and a specific one for each different input, A and B, which inherit from Data. However I've a big problem:
In the code I only want to address the dataset as the Data class, in a
vector<Data> datas;
Data d = new Data();
datas.push_back(d);
and I don't want to do
vector<Data> datas;
Data d = new A();
datas.push_back(d);
but that implies that the parent class will access the child class for the variables, constructors, etc, which I don't now if it's possible (note that the application only reads file A or B, not both in the same execution, I have no problem of setting which at compile time and only add the class A or B to the code)
P.S.: In the original code, written by non computer scientists, they would create the Data class and and an #include "variables.cxx" in its declaration. It obviously works but should be avoided at all costs...