How could I implement a template structure such that I would have let’s say 3 different typedefs for the struct, version1, version2 and version3. The structures all contain a member at the same offset called “version”. Based on the value of this version, how would the template be able to display the correct typedef for this structure?
I’m using this for the header of a binary file to define how the rest of the data in the file will be displayed.
There should be a few different ways to do this. If there are not a lot of differences between the structs you could just use an ‘if’ statement inside the struct and test the version number:
struct MYSTRUCT {
int version;
if( version == 1 )
{
// Define version 1 variables here
}
else if ( version == 2 )
{
// Define version 2 variables here
}
//...
};
Another way is to have different structs defined then pre-read the data with ReadInt to check which one to use:
struct MYSTRUCT1 {
int version;
// Define version 1 variables here
};
struct MYSTRUCT2 {
int version;
// Define version 2 variables here
};
local int version = ReadInt();
if( version == 1 )
MYSTRUCT1 val;
else if( version == 2 )
MYSTRUCT2 val;
If this won’t work for you please provide us with more details on what you are trying to do.
Graeme
SweetScape Software