* Fix FileReader

This commit is contained in:
Phillip Stephens 2014-04-24 19:01:24 -07:00
parent 0d0da95200
commit b7c359ea40
5 changed files with 49 additions and 43 deletions

View File

@ -73,4 +73,11 @@ private:
} // io
} // Athena
#ifndef FILEREADER_BASE
#define FILEREADER_BASE \
private: \
typedef Athena::io::FileReader base;
#endif // FILEREADER_BASE
#endif // FILESTREAM_HPP

View File

@ -69,4 +69,11 @@ private:
};
}
} // Athena
#ifndef FILEWRITER_BASE
#define FILEWRITER_BASE \
private: \
typedef Athena::io::FileWriter base;
#endif // FILEWRITER_BASE
#endif // FILEWRITER_HPP

View File

@ -97,21 +97,21 @@ void BinaryReader::seek(Int64 position, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin::Begin:
if ((position < 0 || (Int64)position > (Int64)m_length))
THROW_IO_EXCEPTION("Position outside stream bounds");
m_position = position;
break;
case SeekOrigin::Current:
if ((((Int64)m_position + position) < 0 || (m_position + position) > m_length))
THROW_IO_EXCEPTION("Position outside stream bounds");
m_position += position;
break;
case SeekOrigin::End:
if ((((Int64)m_length - position < 0) || (m_length - position) > m_length))
THROW_IO_EXCEPTION("Position outside stream bounds");
m_position = m_length - position;
break;
case SeekOrigin::Begin:
if ((position < 0 || (Int64)position > (Int64)m_length))
THROW_IO_EXCEPTION("Position outside stream bounds");
m_position = position;
break;
case SeekOrigin::Current:
if ((((Int64)m_position + position) < 0 || (m_position + position) > m_length))
THROW_IO_EXCEPTION("Position outside stream bounds");
m_position += position;
break;
case SeekOrigin::End:
if ((((Int64)m_length - position < 0) || (m_length - position) > m_length))
THROW_IO_EXCEPTION("Position outside stream bounds");
m_position = m_length - position;
break;
}
}
@ -133,11 +133,7 @@ Uint64 BinaryReader::length() const
void BinaryReader::setData(const Uint8* data, Uint64 length)
{
if (m_data)
#ifdef HW_RVL
free(m_data);
#else
delete[] m_data;
#endif
m_data = (Uint8*)data;
m_length = length;
@ -238,11 +234,7 @@ Uint8* BinaryReader::readUBytes(Int64 length)
THROW_IO_EXCEPTION("Position passed stream bounds");
Uint8* ret;
#ifdef HW_RVL
ret = (Uint8*)memalign(32, length);
#else
ret = new Uint8[length];
#endif
memcpy(ret, (const Uint8*)(m_data + m_position), length);
m_position += length;

View File

@ -196,8 +196,8 @@ Uint16 FileReader::readUint16()
Uint16 val;
fread(&val, 1, sizeof(Uint16), m_fileHandle);
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapU16(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapU16(val);
return val;
}
@ -219,8 +219,8 @@ Uint32 FileReader::readUint32()
Uint32 val;
fread(&val, 1, sizeof(Uint32), m_fileHandle);
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapU64(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapU32(val);
return val;
}
@ -242,8 +242,8 @@ Uint64 FileReader::readUint64()
Uint64 val;
fread(&val, 1, sizeof(Uint64), m_fileHandle);
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapU64(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapU64(val);
return val;
}
@ -265,8 +265,8 @@ double FileReader::readDouble()
double val;
fread(&val, 1, sizeof(double), m_fileHandle);
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapDouble(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapDouble(val);
return val;
}
@ -280,8 +280,8 @@ float FileReader::readFloat()
float val;
fread(&val, 1, sizeof(float), m_fileHandle);
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapFloat(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapFloat(val);
return val;
}

View File

@ -180,8 +180,8 @@ void FileWriter::writeUint16(Uint16 val)
m_bitValid = false;
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapU16(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapU16(val);
if (fwrite(&val, 1, sizeof(Uint16), m_fileHandle) != sizeof(Uint16))
THROW_IO_EXCEPTION("Unable to write to stream");
@ -199,8 +199,8 @@ void FileWriter::writeUint32(Uint32 val)
m_bitValid = false;
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapU32(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapU32(val);
if (fwrite(&val, 1, sizeof(Uint32), m_fileHandle) != sizeof(Uint32))
THROW_IO_EXCEPTION("Unable to write to stream");
@ -218,8 +218,8 @@ void FileWriter::writeUint64(Uint64 val)
m_bitValid = false;
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapU32(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapU32(val);
if (fwrite(&val, 1, sizeof(Uint64), m_fileHandle) != sizeof(Uint64))
THROW_IO_EXCEPTION("Unable to write to stream");
@ -237,8 +237,8 @@ void FileWriter::writeDouble(double val)
m_bitValid = false;
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapDouble(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapDouble(val);
if (fwrite(&val, 1, sizeof(double), m_fileHandle) != sizeof(double))
THROW_IO_EXCEPTION("Unable to write to stream");
@ -251,8 +251,8 @@ void FileWriter::writeFloat(float val)
m_bitValid = false;
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
utility::swapFloat(val);
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
val = utility::swapFloat(val);
if (fwrite(&val, 1, sizeof(float), m_fileHandle) != sizeof(float))
THROW_IO_EXCEPTION("Unable to write to stream");