diff --git a/include/Athena/FileReader.hpp b/include/Athena/FileReader.hpp index ba1765c..13b0d50 100644 --- a/include/Athena/FileReader.hpp +++ b/include/Athena/FileReader.hpp @@ -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 diff --git a/include/Athena/FileWriter.hpp b/include/Athena/FileWriter.hpp index ed8a05b..1c8a0f0 100644 --- a/include/Athena/FileWriter.hpp +++ b/include/Athena/FileWriter.hpp @@ -69,4 +69,11 @@ private: }; } } // Athena + +#ifndef FILEWRITER_BASE +#define FILEWRITER_BASE \ +private: \ + typedef Athena::io::FileWriter base; + +#endif // FILEWRITER_BASE #endif // FILEWRITER_HPP diff --git a/src/Athena/BinaryReader.cpp b/src/Athena/BinaryReader.cpp index 43b9641..11689b9 100644 --- a/src/Athena/BinaryReader.cpp +++ b/src/Athena/BinaryReader.cpp @@ -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; diff --git a/src/Athena/FileReader.cpp b/src/Athena/FileReader.cpp index 1bfc3e2..09b35d3 100644 --- a/src/Athena/FileReader.cpp +++ b/src/Athena/FileReader.cpp @@ -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; } diff --git a/src/Athena/FileWriter.cpp b/src/Athena/FileWriter.cpp index 8066f96..ca73c43 100644 --- a/src/Athena/FileWriter.cpp +++ b/src/Athena/FileWriter.cpp @@ -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");