[Scummvm-cvs-logs] SF.net SVN: scummvm:[54438] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Nov 23 23:26:27 CET 2010


Revision: 54438
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54438&view=rev
Author:   fingolfin
Date:     2010-11-23 22:26:27 +0000 (Tue, 23 Nov 2010)

Log Message:
-----------
COMMON: Add ReadStreamEndian mixin class

Modified Paths:
--------------
    scummvm/trunk/common/memstream.h
    scummvm/trunk/common/stream.h
    scummvm/trunk/common/substream.h

Modified: scummvm/trunk/common/memstream.h
===================================================================
--- scummvm/trunk/common/memstream.h	2010-11-23 22:26:09 UTC (rev 54437)
+++ scummvm/trunk/common/memstream.h	2010-11-23 22:26:27 UTC (rev 54438)
@@ -76,35 +76,13 @@
 
 
 /**
- * This is a wrapper around MemoryReadStream, but it adds non-endian
+ * This is a MemoryReadStream subclass which adds non-endian
  * read methods whose endianness is set on the stream creation.
  */
-class MemoryReadStreamEndian : public MemoryReadStream {
-private:
-	const bool _bigEndian;
-
+class MemoryReadStreamEndian : public MemoryReadStream, public ReadStreamEndian {
 public:
-	MemoryReadStreamEndian(const byte *buf, uint32 len, bool bigEndian = false) : MemoryReadStream(buf, len), _bigEndian(bigEndian) {}
-
-	uint16 readUint16() {
-		uint16 val;
-		read(&val, 2);
-		return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val);
-	}
-
-	uint32 readUint32() {
-		uint32 val;
-		read(&val, 4);
-		return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val);
-	}
-
-	FORCEINLINE int16 readSint16() {
-		return (int16)readUint16();
-	}
-
-	FORCEINLINE int32 readSint32() {
-		return (int32)readUint32();
-	}
+	MemoryReadStreamEndian(const byte *buf, uint32 len, bool bigEndian = false)
+		: MemoryReadStream(buf, len), ReadStreamEndian(bigEndian) {}
 };
 
 /**

Modified: scummvm/trunk/common/stream.h
===================================================================
--- scummvm/trunk/common/stream.h	2010-11-23 22:26:09 UTC (rev 54437)
+++ scummvm/trunk/common/stream.h	2010-11-23 22:26:27 UTC (rev 54438)
@@ -389,6 +389,39 @@
 	virtual String readLine();
 };
 
+/**
+ * This is a ReadStream mixin subclass which adds non-endian read
+ * methods whose endianness is set du the stream creation.
+ */
+class ReadStreamEndian : virtual public ReadStream {
+private:
+	const bool _bigEndian;
+
+public:
+	ReadStreamEndian(bool bigEndian = false) : _bigEndian(bigEndian) {}
+
+	uint16 readUint16() {
+		uint16 val;
+		read(&val, 2);
+		return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val);
+	}
+
+	uint32 readUint32() {
+		uint32 val;
+		read(&val, 4);
+		return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val);
+	}
+
+	FORCEINLINE int16 readSint16() {
+		return (int16)readUint16();
+	}
+
+	FORCEINLINE int32 readSint32() {
+		return (int32)readUint32();
+	}
+};
+
+
 }	// End of namespace Common
 
 #endif

Modified: scummvm/trunk/common/substream.h
===================================================================
--- scummvm/trunk/common/substream.h	2010-11-23 22:26:09 UTC (rev 54437)
+++ scummvm/trunk/common/substream.h	2010-11-23 22:26:27 UTC (rev 54438)
@@ -87,40 +87,18 @@
 };
 
 /**
- * This is a wrapper around SeekableSubReadStream, but it adds non-endian
+ * This is a SeekableSubReadStream subclass which adds non-endian
  * read methods whose endianness is set on the stream creation.
  *
  * Manipulating the parent stream directly /will/ mess up a substream.
  * @see SubReadStream
  */
-class SeekableSubReadStreamEndian : public SeekableSubReadStream {
-private:
-	const bool _bigEndian;
-
+class SeekableSubReadStreamEndian : public SeekableSubReadStream, public ReadStreamEndian {
 public:
 	SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
-		: SeekableSubReadStream(parentStream, begin, end, disposeParentStream), _bigEndian(bigEndian) {
+		: SeekableSubReadStream(parentStream, begin, end, disposeParentStream),
+		  ReadStreamEndian(bigEndian) {
 	}
-
-	uint16 readUint16() {
-		uint16 val;
-		read(&val, 2);
-		return (_bigEndian) ? TO_BE_16(val) : TO_LE_16(val);
-	}
-
-	uint32 readUint32() {
-		uint32 val;
-		read(&val, 4);
-		return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val);
-	}
-
-	FORCEINLINE int16 readSint16() {
-		return (int16)readUint16();
-	}
-
-	FORCEINLINE int32 readSint32() {
-		return (int32)readUint32();
-	}
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list