lots of new streaming interface additions

This commit is contained in:
Jack Andersen 2015-04-10 14:04:13 -10:00
parent e4f5c09534
commit e4f8c2959f
9 changed files with 50 additions and 7 deletions

View File

@ -40,6 +40,7 @@ public:
bool isOpen() const; bool isOpen() const;
bool save(); bool save();
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);}
bool atEnd() const; bool atEnd() const;
atUint64 position() const; atUint64 position() const;
atUint64 length() const; atUint64 length() const;
@ -51,6 +52,8 @@ public:
atInt8 readByte(); atInt8 readByte();
atUint8* readUBytes(atUint64 len); atUint8* readUBytes(atUint64 len);
atInt8* readBytes(atUint64 len); atInt8* readBytes(atUint64 len);
atUint64 readBytesToBuf(void* buf, atUint64 len) {return readUBytesToBuf(buf, len);}
atUint64 readUBytesToBuf(void* buf, atUint64 len);
atUint16 readUint16(); atUint16 readUint16();
atInt16 readInt16(); atInt16 readInt16();
atUint32 readUint32(); atUint32 readUint32();

View File

@ -37,6 +37,7 @@ public:
bool isOpen() const; bool isOpen() const;
bool save(); bool save();
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);}
bool atEnd() const; bool atEnd() const;
atUint64 position() const; atUint64 position() const;
atUint64 length() const; atUint64 length() const;

View File

@ -59,6 +59,9 @@
#define BLOCKSZ 512 #define BLOCKSZ 512
#endif #endif
#define ROUND_UP_32(val) (((val) + 31) & ~31)
#define ROUND_UP_16(val) (((val) + 15) & ~15)
namespace Athena namespace Athena
{ {
enum class SeekOrigin enum class SeekOrigin

View File

@ -17,6 +17,7 @@ public:
virtual bool isLittleEndian()const= 0; virtual bool isLittleEndian()const= 0;
virtual bool isOpen() const= 0; virtual bool isOpen() const= 0;
virtual void seek(atInt64, SeekOrigin)=0; virtual void seek(atInt64, SeekOrigin)=0;
virtual void seekAlign32()=0;
virtual bool atEnd() const= 0; virtual bool atEnd() const= 0;
virtual atUint64 position() const= 0; virtual atUint64 position() const= 0;
virtual atUint64 length() const= 0; virtual atUint64 length() const= 0;
@ -26,6 +27,8 @@ public:
virtual atInt8 readByte()=0; virtual atInt8 readByte()=0;
virtual atUint8* readUBytes(atUint64)=0; virtual atUint8* readUBytes(atUint64)=0;
virtual atInt8* readBytes(atUint64)=0; virtual atInt8* readBytes(atUint64)=0;
virtual atUint64 readUBytesToBuf(void*, atUint64)=0;
virtual atUint64 readBytesToBuf(void*, atUint64)=0;
virtual atUint16 readUint16()=0; virtual atUint16 readUint16()=0;
virtual atInt16 readInt16()=0; virtual atInt16 readInt16()=0;
virtual atUint32 readUint32()=0; virtual atUint32 readUint32()=0;

View File

@ -17,6 +17,7 @@ public:
virtual bool isLittleEndian()const= 0; virtual bool isLittleEndian()const= 0;
virtual bool isOpen() const= 0; virtual bool isOpen() const= 0;
virtual void seek(atInt64, SeekOrigin)=0; virtual void seek(atInt64, SeekOrigin)=0;
virtual void seekAlign32()=0;
virtual bool atEnd() const= 0; virtual bool atEnd() const= 0;
virtual atUint64 position() const= 0; virtual atUint64 position() const= 0;
virtual atUint64 length() const= 0; virtual atUint64 length() const= 0;

View File

@ -87,6 +87,9 @@ public:
*/ */
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! \brief Sets the buffers position relative to the next 32-byte aligned position.<br />
*/
inline void seekAlign32() {seek(ROUND_UP_32(m_position), SeekOrigin::Begin);}
/*! \brief Returns whether or not the stream is at the end. /*! \brief Returns whether or not the stream is at the end.
* *
@ -167,7 +170,7 @@ public:
* *
* \return Uint8* The buffer at the current position from the given length. * \return Uint8* The buffer at the current position from the given length.
*/ */
atInt8* readBytes(atUint64 length); inline atInt8* readBytes(atUint64 length) {return (atInt8*)readUBytes(length);}
/*! \brief Reads a byte at the current position and advances the current position. /*! \brief Reads a byte at the current position and advances the current position.
* *
@ -175,6 +178,9 @@ public:
*/ */
atUint8* readUBytes(atUint64 length); atUint8* readUBytes(atUint64 length);
atUint64 readBytesToBuf(void* buf, atUint64 len) {return readUBytesToBuf(buf, len);}
atUint64 readUBytesToBuf(void* buf, atUint64 len);
/*! \brief Reads a Int16 and swaps to proper endianness depending on platform /*! \brief Reads a Int16 and swaps to proper endianness depending on platform
* and Stream settings, and advances the current position * and Stream settings, and advances the current position
* *

View File

@ -88,6 +88,10 @@ public:
*/ */
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current); void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! \brief Sets the buffers position relative to the next 32-byte aligned position.<br />
*/
inline void seekAlign32() {seek(ROUND_UP_32(m_position), SeekOrigin::Begin);}
/*! \brief Returns whether or not the stream is at the end. /*! \brief Returns whether or not the stream is at the end.
* *

View File

@ -186,6 +186,14 @@ atUint8* FileReader::readUBytes(atUint64 len)
return val; return val;
} }
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
{
if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for reading");
m_bitValid = false;
return fread(buf, 1, len, m_fileHandle);
}
atInt8* FileReader::readBytes(atUint64 len) atInt8* FileReader::readBytes(atUint64 len)
{ {
if (!isOpen()) if (!isOpen())

View File

@ -224,11 +224,6 @@ atUint8 MemoryReader::readUByte()
return *(atUint8*)(m_data + m_position++); return *(atUint8*)(m_data + m_position++);
} }
atInt8* MemoryReader::readBytes(atUint64 length)
{
return (atInt8*)readUBytes(length);
}
atUint8* MemoryReader::readUBytes(atUint64 length) atUint8* MemoryReader::readUBytes(atUint64 length)
{ {
if (!m_data) if (!m_data)
@ -251,6 +246,25 @@ atUint8* MemoryReader::readUBytes(atUint64 length)
return ret; return ret;
} }
atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length)
{
if (!m_data)
loadData();
if (m_bitPosition > 0)
{
m_bitPosition = 0;
m_position += sizeof(atUint8);
}
if (m_position + length > m_length)
THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position);
memcpy(buf, (const atUint8*)(m_data + m_position), length);
m_position += length;
return length;
}
atInt16 MemoryReader::readInt16() atInt16 MemoryReader::readInt16()
{ {
if (!m_data) if (!m_data)