A
Anil
Hi,
I'm trying to come up with a way to improve upon the following.
enum Label_Type
{
Label1,
Label2,
// ...
};
enum Key_Transform_Type
{
key1_key3,
key2_key4,
// ...
};
// key to scheme mapping
Key1 => { Label1, Label2, Label3, Label5, Label7 };
Key2 => { Label4, Label6, Label7 };
// map for converting from schemeA to schemeB
{ Key1, Key2, key1_key2 }
{ Key3, Key4, key3_key4 }
class test
{
// array of values referenced by labels
};
const test& test:perator = ( const test& src )
{
// ...
Key_Transform_Type TransformType = GetTransformType(
src.GetKeyType(), GetKeyType() );
switch ( TransformType )
{
case key1_key2:
Value(Label4) = src.Value(Label1) + src.Value(Label3);
Value(Label6) = src.Value(Label2) + src.Value(Label5);
Value(Label7) = src.Value(Label7);
break;
// handle other cases
}
return (*this);
}
The basic problem is to convert values in one scheme to another and it
has to be 'fast' as well. The code is littered with switch/case
statements and there're quite a few conversion scenarios.
Since the conversion is known at compile time, could templates be used
to express the relationship between the various schemes?
Any ideas?
Thanks
AK
I'm trying to come up with a way to improve upon the following.
enum Label_Type
{
Label1,
Label2,
// ...
};
enum Key_Transform_Type
{
key1_key3,
key2_key4,
// ...
};
// key to scheme mapping
Key1 => { Label1, Label2, Label3, Label5, Label7 };
Key2 => { Label4, Label6, Label7 };
// map for converting from schemeA to schemeB
{ Key1, Key2, key1_key2 }
{ Key3, Key4, key3_key4 }
class test
{
// array of values referenced by labels
};
const test& test:perator = ( const test& src )
{
// ...
Key_Transform_Type TransformType = GetTransformType(
src.GetKeyType(), GetKeyType() );
switch ( TransformType )
{
case key1_key2:
Value(Label4) = src.Value(Label1) + src.Value(Label3);
Value(Label6) = src.Value(Label2) + src.Value(Label5);
Value(Label7) = src.Value(Label7);
break;
// handle other cases
}
return (*this);
}
The basic problem is to convert values in one scheme to another and it
has to be 'fast' as well. The code is littered with switch/case
statements and there're quite a few conversion scenarios.
Since the conversion is known at compile time, could templates be used
to express the relationship between the various schemes?
Any ideas?
Thanks
AK