aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/memstream.h30
-rw-r--r--common/stream.h33
-rw-r--r--common/substream.h30
3 files changed, 41 insertions, 52 deletions
diff --git a/common/memstream.h b/common/memstream.h
index 5ba259b842..d6a55c3b75 100644
--- a/common/memstream.h
+++ b/common/memstream.h
@@ -76,35 +76,13 @@ public:
/**
- * 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) {}
};
/**
diff --git a/common/stream.h b/common/stream.h
index 1dceb31f16..141e37529c 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -389,6 +389,39 @@ public:
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
diff --git a/common/substream.h b/common/substream.h
index cf794cfa7e..8c9c56165e 100644
--- a/common/substream.h
+++ b/common/substream.h
@@ -87,39 +87,17 @@ public:
};
/**
- * 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) {
- }
-
- 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();
+ : SeekableSubReadStream(parentStream, begin, end, disposeParentStream),
+ ReadStreamEndian(bigEndian) {
}
};