I'm using better enums package
Having 1:1 mapping between better enum values and better enum types/functionality
For example
- better enum A[a1, a2]
- better enum B1
- better enum B2
So the logical mapping is:
- A::a1 mapped to B1 type
- A:a2 mapped to B2 type
BETTER_ENUM(A, int, a1, a2)
BETTER_ENUM(B1, int, b11, b12, b13)
BETTER_ENUM(B2, int, b21, b22, b23, b24)
Obviously the above example is of size two, but real code would have to support its growth
So basically in order to support this mapping used switch case as below, but this code is hard to maintain and extend:
bool Execute1(A a_val)
{
switch (a_val)
{
case A::a1:
return execute1<B1>();
case A::a2:
return execute1<B2>();
default:
break;
}
return false;
}
int Execute2(A a_val)
{
switch (a_val)
{
case A::a1:
return execute2<B1>();
case A::a2:
return execute2<B2>();
default:
break;
}
return 0;
}
Any ideas how to generalize this mapping , and use some design pattern that doesn't require as above switch/case?