The function "fetch_block()" could be written differently. You'll need to check if this one is more efficient.
Code:
//fetch_block() assumes a block is:
// a) Starts with a double.
// b) After a double, it continues with unknown numbers of unsinged ints.
//End if newline or EOF is found.
void fetch_block(ifstream& ifs, double& time, vector<unsigned>& vec)
{
unsigned val;
char ch = ifs.peek();
//Previous calls of this method leaves a newline behind. Test and remove if so.
if(ch == '\n')
{
ifs.get(ch);
}
//We end up here if newline is removed/non-exist.
//Fetch double from block if file is not empty.
if( ifs>>time )
{
// "istream/ifstream >> variable" leaves a newline behind. Remove it.
ifs.get(ch);
//Now fetch the rest of the block if any unsigned is present.
ch = ifs.peek();
//Stop at next newline (or EOF obviously).
//If there is a next newline, then that must be a second newline: our very
//"block delimiter". We only want to fetch a single block!
while( ch != '\n' && ch != EOF )
{
ifs>>hex>>val;
ifs.get(ch);
vec.push_back(val);
ch=ifs.peek();
}
}
}