aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLe Philousophe2019-03-05 19:27:52 +0100
committerEugene Sandulenko2019-06-01 22:43:48 +0200
commit97397bdaffed7f7bdf97ccde20bbcd41df4e63fb (patch)
tree7fd702b2879993fa6aa81c4534cb5eb4369e1c1e
parent438a6223cbb5a822aa3506352e743e20f4d2da6e (diff)
downloadscummvm-rg350-97397bdaffed7f7bdf97ccde20bbcd41df4e63fb.tar.gz
scummvm-rg350-97397bdaffed7f7bdf97ccde20bbcd41df4e63fb.tar.bz2
scummvm-rg350-97397bdaffed7f7bdf97ccde20bbcd41df4e63fb.zip
STREAM: add read/write functions for double LE/BE
-rw-r--r--common/stream.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/common/stream.h b/common/stream.h
index dfb7d6c9b2..16264a7f14 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -204,6 +204,31 @@ public:
}
/**
+ * Write the given 64-bit floating point value stored
+ * in little endian(LSB first) order into the stream.
+ */
+ FORCEINLINE void writeDoubleLE(double value) {
+ uint64 n;
+
+ memcpy(&n, &value, 8);
+
+ writeUint64LE(n);
+ }
+
+
+ /**
+ * Write the given 64-bit floating point value stored
+ * in big endian order into the stream.
+ */
+ FORCEINLINE void writeDoubleBE(double value) {
+ uint64 n;
+
+ memcpy(&n, &value, 8);
+
+ writeUint64BE(n);
+ }
+
+ /**
* Write the given string to the stream.
* This writes str.size() characters, but no terminating zero byte.
*/
@@ -474,6 +499,39 @@ public:
return f;
}
+
+ /**
+ * Read a 64-bit floating point value stored in little endian (LSB first)
+ * order from the stream and return it.
+ * Performs no error checking. The return value is undefined
+ * if a read error occurred (for which client code can check by
+ * calling err() and eos() ).
+ */
+ FORCEINLINE double readDoubleLE() {
+ uint64 n = readUint64LE();
+ double d;
+
+ memcpy(&d, &n, 8);
+
+ return d;
+ }
+
+ /**
+ * Read a 64-bit floating point value stored in big endian
+ * order from the stream and return it.
+ * Performs no error checking. The return value is undefined
+ * if a read error occurred (for which client code can check by
+ * calling err() and eos() ).
+ */
+ FORCEINLINE double readDoubleBE() {
+ uint64 n = readUint64BE();
+ double d;
+
+ memcpy(&d, &n, 8);
+
+ return d;
+ }
+
/**
* Read the specified amount of data into a malloc'ed buffer
* which then is wrapped into a MemoryReadStream.