[Scummvm-cvs-logs] CVS: scummvm/common stream.cpp,1.2,1.3 stream.h,1.4,1.5

Eugene Sandulenko sev at users.sourceforge.net
Mon May 3 20:28:07 CEST 2004


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9732

Modified Files:
	stream.cpp stream.h 
Log Message:
Enchance ReadStream and MemoryReadStream with 24bits operations as well
as tell() and rewind() methods, as needed by SAGA engine.


Index: stream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/stream.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- stream.cpp	29 Apr 2004 20:28:42 -0000	1.2
+++ stream.cpp	4 May 2004 03:27:00 -0000	1.3
@@ -34,12 +34,24 @@
 	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();
@@ -52,6 +64,12 @@
 	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();
@@ -63,6 +81,10 @@
 	return (int16)readUint16LE();
 }
 
+int32 ReadStream::readSint24LE() {
+	return (int32)readUint24LE();
+}
+
 int32 ReadStream::readSint32LE() {
 	return (int32)readUint32LE();
 }
@@ -71,6 +93,10 @@
 	return (int16)readUint16BE();
 }
 
+int32 ReadStream::readSint24BE() {
+	return (int32)readUint24BE();
+}
+
 int32 ReadStream::readSint32BE() {
 	return (int32)readUint32BE();
 }
@@ -81,11 +107,20 @@
 	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));
@@ -96,6 +131,11 @@
 	writeByte((byte)(value & 0xff));
 }
 
+void WriteStream::writeUint24BE(uint32 value) {
+	writeByte((byte)(value >> 16));
+	writeUint16BE((uint16)(value & 0xffff));
+}
+
 void WriteStream::writeUint32BE(uint32 value) {
 	writeUint16BE((uint16)(value >> 16));
 	writeUint16BE((uint16)(value & 0xffff));
@@ -106,6 +146,10 @@
 	writeUint16LE((uint16)value);
 }
 
+void WriteStream::writeSint24LE(int32 value) {
+	writeUint24LE((uint32)value);
+}
+
 void WriteStream::writeSint32LE(int32 value) {
 	writeUint32LE((uint32)value);
 }
@@ -114,6 +158,10 @@
 	writeUint16BE((uint16)value);
 }
 
+void WriteStream::writeSint24BE(int32 value) {
+	writeUint24BE((uint32)value);
+}
+
 void WriteStream::writeSint32BE(int32 value) {
 	writeUint32BE((uint32)value);
 }

Index: stream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/stream.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- stream.h	3 May 2004 23:08:22 -0000	1.4
+++ stream.h	4 May 2004 03:27:00 -0000	1.5
@@ -36,17 +36,22 @@
 	// The remaining methods all have default implementations
 
 	void writeByte(byte value);
+	void writeSByte(int8 value);
 
 	void writeUint16LE(uint16 value);
+	void writeUint24LE(uint32 value);
 	void writeUint32LE(uint32 value);
 
 	void writeUint16BE(uint16 value);
+	void writeUint24BE(uint32 value);
 	void writeUint32BE(uint32 value);
 
 	void writeSint16LE(int16 value);
+	void writeSint24LE(int32 value);
 	void writeSint32LE(int32 value);
 
 	void writeSint16BE(int16 value);
+	void writeSint24BE(int32 value);
 	void writeSint32BE(int32 value);
 };
 
@@ -58,17 +63,22 @@
 	// The remaining methods all have default implementations
 
 	byte readByte();
+	int8 readSByte();
 
 	uint16 readUint16LE();
+	uint32 readUint24LE();
 	uint32 readUint32LE();
 
 	uint16 readUint16BE();
+	uint32 readUint24BE();
 	uint32 readUint32BE();
 
 	int16 readSint16LE();
+	int32 readSint24LE();
 	int32 readSint32LE();
 
 	int16 readSint16BE();
+	int32 readSint24BE();
 	int32 readSint32BE();
 };
 
@@ -109,9 +119,12 @@
 class MemoryReadStream : public ReadStream {
 private:
 	const byte *_ptr;
+	const byte *_ptrOrig;
 	uint32 _size;
+	uint32 _sizeOrig;
+	uint32 _pos;
 public:
-	MemoryReadStream(const byte *ptr, uint32 size) : _ptr(ptr), _size(size) {}
+	MemoryReadStream(const byte *ptr, uint32 size) : _ptr(ptr), _ptrOrig(ptr), _size(size), _sizeOrig(size), _pos(0) {}
 
 	uint32 read(void *ptr, uint32 size) {
 		if (size > _size)
@@ -119,8 +132,17 @@
 		memcpy(ptr, _ptr, size);
 		_size -= size;
 		_ptr += size;
+		_pos += size;
 		return size;
 	}
+
+	uint32 tell() { return _pos; }
+
+	void rewind() {
+		_ptr = _ptrOrig;
+		_size = _sizeOrig;
+		_pos = 0;
+	}
 };
 
 }	// End of namespace Common





More information about the Scummvm-git-logs mailing list