aboutsummaryrefslogtreecommitdiff
path: root/common/stream.cpp
diff options
context:
space:
mode:
authorMax Horn2004-12-11 23:16:36 +0000
committerMax Horn2004-12-11 23:16:36 +0000
commit369e31a41c87a38da018a3350da53dd914a7065e (patch)
tree08c2db8449beb21769529a649c6346d3b0d6cd3e /common/stream.cpp
parentff2e6565d1a0e6c2d8c6906496799b9a05d0d52f (diff)
downloadscummvm-rg350-369e31a41c87a38da018a3350da53dd914a7065e.tar.gz
scummvm-rg350-369e31a41c87a38da018a3350da53dd914a7065e.tar.bz2
scummvm-rg350-369e31a41c87a38da018a3350da53dd914a7065e.zip
Modified version of patch #1082777 (common/stream optimization)
svn-id: r16034
Diffstat (limited to 'common/stream.cpp')
-rw-r--r--common/stream.cpp159
1 files changed, 21 insertions, 138 deletions
diff --git a/common/stream.cpp b/common/stream.cpp
index 11cce2a4cd..6a8836c7b0 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -24,146 +24,29 @@
namespace Common {
-/* TODO:
- * - The ReadStream / WriteStream should provide some error handling
- */
-
-byte ReadStream::readByte() {
- byte b = 0;
- read(&b, 1);
- return b;
-}
-
-int8 ReadStream::readSByte() {
- int8 b = 0;
- read(&b, 1);
- return b;
-}
-
-uint16 ReadStream::readUint16LE() {
- uint16 a = readByte();
- uint16 b = readByte();
- return a | (b << 8);
-}
-
-uint32 ReadStream::readUint24LE() {
- uint32 a = readUint16LE();
- uint32 b = readByte();
- return (b << 16) | a;
-}
-
-uint32 ReadStream::readUint32LE() {
- uint32 a = readUint16LE();
- uint32 b = readUint16LE();
- return (b << 16) | a;
-}
-
-uint16 ReadStream::readUint16BE() {
- uint16 b = readByte();
- uint16 a = readByte();
- return a | (b << 8);
-}
-
-uint32 ReadStream::readUint24BE() {
- uint32 b = readByte();
- uint32 a = readUint16BE();
- return (b << 16) | a;
-}
-
-uint32 ReadStream::readUint32BE() {
- uint32 b = readUint16BE();
- uint32 a = readUint16BE();
- return (b << 16) | a;
-}
-
-
-int16 ReadStream::readSint16LE() {
- return (int16)readUint16LE();
-}
-
-int32 ReadStream::readSint24LE() {
- return (int32)readUint24LE();
-}
-
-int32 ReadStream::readSint32LE() {
- return (int32)readUint32LE();
-}
-
-int16 ReadStream::readSint16BE() {
- return (int16)readUint16BE();
-}
-
-int32 ReadStream::readSint24BE() {
- return (int32)readUint24BE();
-}
-
-int32 ReadStream::readSint32BE() {
- return (int32)readUint32BE();
-}
-
-
-
-void WriteStream::writeByte(byte value) {
- write(&value, 1);
-}
-
-void WriteStream::writeSByte(int8 value) {
- write(&value, 1);
-}
-
-void WriteStream::writeUint16LE(uint16 value) {
- writeByte((byte)(value & 0xff));
- writeByte((byte)(value >> 8));
-}
-
-void WriteStream::writeUint24LE(uint32 value) {
- writeUint16LE((uint16)(value & 0xffff));
- writeByte((byte)(value >> 16));
-}
-
-void WriteStream::writeUint32LE(uint32 value) {
- writeUint16LE((uint16)(value & 0xffff));
- writeUint16LE((uint16)(value >> 16));
-}
-
-void WriteStream::writeUint16BE(uint16 value) {
- writeByte((byte)(value >> 8));
- writeByte((byte)(value & 0xff));
-}
-void WriteStream::writeUint24BE(uint32 value) {
- writeByte((byte)(value >> 16));
- writeUint16BE((uint16)(value & 0xffff));
+void MemoryReadStream::seek(uint32 offs, int whence) {
+ // Pre-Condition
+ assert(_pos <= _bufSize);
+ switch (whence) {
+ case SEEK_END:
+ // SEEK_END works just like SEEK_SET, only 'reversed',
+ // i.e. from the end.
+ offs = _bufSize - offs;
+ // Fall through
+ case SEEK_SET:
+ _ptr = _ptrOrig + offs;
+ _pos = offs;
+ break;
+
+ case SEEK_CUR:
+ _ptr += offs;
+ _pos += offs;
+ break;
+ }
+ // Post-Condition
+ assert(_pos <= _bufSize);
}
-void WriteStream::writeUint32BE(uint32 value) {
- writeUint16BE((uint16)(value >> 16));
- writeUint16BE((uint16)(value & 0xffff));
-}
-
-
-void WriteStream::writeSint16LE(int16 value) {
- writeUint16LE((uint16)value);
-}
-
-void WriteStream::writeSint24LE(int32 value) {
- writeUint24LE((uint32)value);
-}
-
-void WriteStream::writeSint32LE(int32 value) {
- writeUint32LE((uint32)value);
-}
-
-void WriteStream::writeSint16BE(int16 value) {
- writeUint16BE((uint16)value);
-}
-
-void WriteStream::writeSint24BE(int32 value) {
- writeUint24BE((uint32)value);
-}
-
-void WriteStream::writeSint32BE(int32 value) {
- writeUint32BE((uint32)value);
-}
} // End of namespace Common