I am trying to open raw data file(s) that contain some numbers using VC++. The numbers could be 8/16/24 bit. I have a prior knowledge of that for a given file.
Can I use C++ templates to create array variables to store numbers read from files based on what bit-depth they are? Something on the lines of this pseudo code:
if(BitDepth==8)
{
CTemplate<unsigned byte> data; // data type should be unsigned byte
Read8Bit(data);
//.. various ops to read 8 bit data
}
if(BitDepth==16)
{
CTemplate<unsigned short> data; // data type should be unsigned short
Read16Bit(data);
//.. various ops to read 16 bit data
}
if(BitDepth==24)
{
CTemplate<unsigned int> data; // data type should be unsigned int
Read24Bit(data);
//.. various ops to read 24 bit data
}
//Later use 'data' out of scope of if() conditionals
Of course, the template variable 'data' has to be used outside the scope of the if() conditionals later. So I need to declare 'data' as a global (say, in header). Am loosing track here...