Game Development Reference
In-Depth Information
the file is corrupted. Either way the function returns -1 to indicate an error
after showing a message box. The other exit condition occurs if the value
count reaches zero. The variable count is incremented if { is found in the
string read from the file and decremented if } is found. If count reaches
zero the variable end is used to record the file position. Then the loop is
exited and the file is returned to the original position using the variable
start .
int C3DSAscii::GetSectionEnd(CStdioFile &file)
{
CString line;
int end, start = file.GetPosition(), count=1; //First brace
assumed while(1){
if (!file.ReadString(line)){
AfxMessageBox("Matching brace not found in file,
wrong data format");
end = -1;
break;
}
if (line.Find("{")!=-1) count++;
if (line.Find("}")!=-1) count-;
if (!count){
end = file.GetPosition();
break;
}
}
//Return file position back to initial location
file.Seek(start,CFile::begin);
return end;
}
Each line in an ASE file contains tokens separated by either spaces or
tabs. The purpose of the utility function ParseTokens is to take a string
stored in an MFC CString and a string array defined as TOKENS and to
split the string up into substrings stored in the TOKEN array. Because we
could try to write to an index in the array out of bounds, the final parameter
used in the ParseTokens function is maxtokens , defining the TOKEN limit.
The first step is to clear any white space characters at the beginning or
end of the line string. Then the function enters a loop examining each
character in the line string in turn. If the character is a space or a tab then
we have found the end of a substring. The loop first gets the next
character to be examined. If this is not a space or a tab then it is added
Search Nedrilad ::




Custom Search