I'm writing an interface between two configuration models that use different structures. While I know that there is no "magic" way to do the translation from a structure type to another, I wandered if there might be some best practices or an efficient/effective way to setup such a system. I think it's similar to how programs may manage different configuration structures accross versions.
Here's a simple example: let's say we have a structure of type A which contains 3 parameters:
struct A {
int alpha;
bool beta;
bool charlie;
};
The second configuration structure share the same parameters, but in a different order, let's see structure B:
struct B {
union {
struct {
char beta : 1;
char charlie : 1;
} bit;
char field;
}
int alpha;
};
A simple program to convert an A to a B would be:
void convert(A const *aelem, B *belem) {
belem->alpha = aelem->alpha;
belem->bit.beta = aelem->beta;
belem->bit.charlie = aelem->charlie;
}
So, while this may seem fairly simple with such basic structures, I'm dealing with dozens of structures, each of one contains around 50 parameters. So do anybody knows of a good pattern to follow for such a problem ?