I am in a situation where I have to produce C++ code that is going to be used from the JNI. I have defined along with the java peers the right structure to pass data. However there is a legacy, hacky and super ugly structure that I was asked to use instead of the clean structure designed. So I have something like:
struct NiceStructure{
int a;
int b;
bool c;
};
struct LegacyStructure{
string a;
double b;
bool c;
int old_dont_use;
string type;
int I_dont_remember_what_this_is_but_dont_touch_it;
bool clip;
};
The NiceStructure
is well suited for the operations I want to perform and the LegacyStructure
can be hacked (like it has traditionally been) to do what I want to do.
The question is: Can I program a type agnostic function that can deal with both structures?
An example function would be:
vector<NiceStructure> do_something(vector<NiceStructure> array_of_values){
vector<NiceStructure> res;
for (int i=0; i< array_of_values.size(); i++){
if (array_of_values[i].a + array_of_values[i].b > 10 && array_of_values[i].c)
res.push_back(array_of_values[i])
}
return res;
}
I should be able to change the type NiceStructure
by LegacyStructure
and work with either of them somehow.