diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index 6733a89f4b..0450588d9a 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -788,6 +788,12 @@ void hsReadOnlyStream::CopyToMem(void* mem) //////////////////////////////////////////////////////////////////////////////////// + +bool hsWriteOnlyStream::AtEnd() +{ + return fData >= fStop; +} + uint32_t hsWriteOnlyStream::Read(uint32_t byteCount, void* buffer) { hsThrow( "can't read to a writeonly stream"); @@ -804,6 +810,39 @@ uint32_t hsWriteOnlyStream::Write(uint32_t byteCount, const void* buffer) return byteCount; } +void hsWriteOnlyStream::Skip(uint32_t deltaByteCount) +{ + fPosition += deltaByteCount; + fData += deltaByteCount; + if (fData > fStop) { + hsThrow("Skip went past end of stream"); + } +} + +void hsWriteOnlyStream::Rewind() +{ + fPosition = 0; + fData = fStart; +} + +void hsWriteOnlyStream::FastFwd() +{ + fPosition = GetEOF(); + fData = fStop; +} + +void hsWriteOnlyStream::Truncate() +{ + hsThrow("can't write to a readonly stream"); +} + +void hsWriteOnlyStream::CopyToMem(void* mem) +{ + if (fData < fStop) { + memmove(mem, fData, fStop - fData); + } +} + /////////////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/CoreLib/hsStream.h b/Sources/Plasma/CoreLib/hsStream.h index 272baaa5ef..609da689dc 100644 --- a/Sources/Plasma/CoreLib/hsStream.h +++ b/Sources/Plasma/CoreLib/hsStream.h @@ -260,12 +260,14 @@ class hsNullStream : public hsStream { // read only mem stream class hsReadOnlyStream : public hsStream { protected: - char* fStart; - char* fData; - char* fStop; + const char* fStart; + const char* fData; + const char* fStop; public: - hsReadOnlyStream(int size, const void* data) - : fStart((char*)data), fData((char*)data), fStop((char*)data + size) + hsReadOnlyStream(int size, const void* data) : + fStart(static_cast(data)), + fData(static_cast(data)), + fStop(static_cast(data) + size) {} bool AtEnd() override; @@ -280,17 +282,33 @@ class hsReadOnlyStream : public hsStream { }; // write only mem stream -class hsWriteOnlyStream : public hsReadOnlyStream { +class hsWriteOnlyStream : public hsStream { +protected: + char* fStart; + char* fData; + char* fStop; + public: - hsWriteOnlyStream(int size, const void* data) : hsReadOnlyStream(size, data) {} + hsWriteOnlyStream(int size, void* data) : + fStart(static_cast(data)), + fData(static_cast(data)), + fStop(static_cast(data) + size) + {} hsWriteOnlyStream(const hsWriteOnlyStream& other) = delete; hsWriteOnlyStream(hsWriteOnlyStream&& other) = delete; const hsWriteOnlyStream& operator=(const hsWriteOnlyStream& other) = delete; hsWriteOnlyStream& operator=(hsWriteOnlyStream&& other) = delete; + bool AtEnd() override; uint32_t Read(uint32_t byteCount, void * buffer) override; // throws exception uint32_t Write(uint32_t byteCount, const void* buffer) override; + void Skip(uint32_t deltaByteCount) override; + void Rewind() override; + void FastFwd() override; + void Truncate() override; + uint32_t GetEOF() override { return (uint32_t)(fStop - fStart); } + void CopyToMem(void* mem); }; // circular queue stream