Often I have to face the problem of matching the parameter space of one API in the parameter space of another. Often I see that this is solved using nested nested nested ... switch statements.
And I was wondering if there would be a library or a technique that allows you to "declare" a mapping instead of a "program."
A trivial example would be to combine the values โโof two enumerations into one:
namespace sourceAPI { struct A { typedef e { A1, A2, A3 } }; struct B { typedef e { B1, B2 } }; } namespace targetAPI { struct AB { typedef e { A1B1, A1B2, A2B1, A2B2, A3B1, A3B2 } }; }
In which the display is often performed, for example,
switch( a ){ case( A::A1 ): switch( b ) { case( B::B1 ): return A1B1; case( B::B2 ): return A1B2; .... }
And this display still needs a "reverse" switch.
But I would like something "dense" like
declare( source( A::A1, B::B1 ), target( AB::A1B1 ) ); declare( source( A::A1, B::B2 ), target( AB::A1B2 ) ); ....
Has anyone seen such a technique or structure or library?
source share