struct StandardFileHeader
{
char* fileType;
int formatVersion;
std::string name;
std::string author;
std::string description;
std::string creationProgram;
};
(note, the formatting is kind of screwed up)
StandardFileHeader FileIoHandle::LoadStandardHeader()
{
StandardFileHeader header;
int nameSize, authorSize, descSize, creatorSize;
char* name, *author, *desc, *creator;
ToBeginning();
header.fileType = GetChunk<char>(8);
header.formatVersion = GetChunk<int>();
nameSize = GetChunk<int>();
name = GetChunk<char>(nameSize);
authorSize = GetChunk<int>();
author = GetChunk<char>(authorSize);
descSize = GetChunk<int>();
desc = GetChunk<char>(descSize);
creatorSize = GetChunk<int>();
creator = GetChunk<char>(creatorSize);
header.name = name;
header.author = author;
header.description = desc;
header.creationProgram = creator;
return header;
}
void FileIoHandle::PutStandardHeader
(const std::string& fileType, int formatVersion, const std::string& name,
const std::string& author, const std::string& description,
const std::string& creationProgram)
{
ToBeginning();
PutString(fileType.c_str(), 8);
PutChunk<int>(formatVersion);
PutChunk<int>(name.size());
PutString(name.c_str(), name.size());
PutChunk<int>(author.size());
PutString(author.c_str(), author.size());
PutChunk<int>(description.size());
PutString(description.c_str(), description.size());
PutChunk<int>(creationProgram.size());
PutString(creationProgram.c_str(), creationProgram.size());
}
bool FileIoTestWrite()
{
using namespace stratus;
using namespace base;
FileIoHandle* File = new FileIoHandle();
File->Open("testFile.txt");
File->PutStandardHeader("testfil", 27, "Test File",
"Grant Williams",
"This is a file for testing",
"FileIo library");
File->Close();
delete File;
}
bool FileIoTestRead()
{
using namespace stratus;
using namespace base;
using namespace std;
FileIoHandle* File = new FileIoHandle();
if(!File->Open("testFile.txt"))
return false;
StandardFileHeader header;
header = File->LoadStandardHeader();
cout << File->GetFileName() << endl
<< File->GetFileSize() << endl << endl;
cout << header.fileType << endl
<< header.formatVersion << endl
<< header.name << endl
<< header.author << endl
<< header.description << endl
<< header.creationProgram << endl;
File->Close();
delete File;
}
testFile.txt
127
testfil
27
Test File
Grant Williams
This is a file for testing
FileIo library
but instead I get:
testFile.txt
127
testfil
27
Test File
Grant Williams
I can't for the life of me figure out why the description and creation method
don't show up. Can anyone help?
I hope it's not a stupid mistake =/