changes for otb compability

This commit is contained in:
Eduardo Bart
2012-06-21 14:54:20 -03:00
parent f3499efe83
commit 96c363d997
35 changed files with 1354 additions and 791 deletions

View File

@@ -137,7 +137,7 @@ bool FileStream::seek(int pos)
int FileStream::size()
{
if(m_fileHandle)
if(m_fileHandle)
return PHYSFS_fileLength(m_fileHandle);
else
return m_cacheBuffer.size();
@@ -249,28 +249,30 @@ std::string FileStream::getString()
return str;
}
uint8 FileStream::readNode(uint8 &oldNode, uint32 &type)
uint8 FileStream::readFirstNode(uint32& type)
{
if (!oldNode) {
if ((oldNode = getU8()) == 0xFE) {
type = getU32();
return oldNode;
} else {
dump << "Failed to read new node.";
return 0;
}
}
dump << "first";
uint8 node = getU8();
if(node != NODE_START)
stdext::throw_exception("failed to read first node");
type = getU32();
return node;
}
assert(getU8() == 0xFF);
if ((oldNode = getU8()) == 0xFE) {
type = getU32();
return oldNode;
} else {
dump << "Failed to read node with old type: " << type;
return 0;
}
uint8 FileStream::readNextNode(uint8 oldNode, uint32& type)
{
dump << "next";
// end of old node
if(getU8() != NODE_END)
stdext::throw_exception("node not ended");
return 0;
// next node
uint8 node = getU8();
if(oldNode != NODE_START)
stdext::throw_exception("invalid node start");
type = getU32();
return node;
}
void FileStream::addU8(uint8 v)

View File

@@ -29,6 +29,12 @@ struct PHYSFS_File;
class FileStream
{
enum {
NODE_START = 0xFE,
NODE_END = 0xFF,
ESCAPE_CHAR = 0xFD,
};
protected:
FileStream(const std::string& name, PHYSFS_File *fileHandle);
@@ -59,7 +65,9 @@ public:
void addU32(uint8 v);
void addU64(uint8 v);
uint8 readNode(uint8 &oldNode, uint32 &type);
uint8 readFirstNode(uint32& type);
uint8 readNextNode(uint8 oldNode, uint32& type);
private:
std::string m_name;
PHYSFS_File *m_fileHandle;