diff options
author | yinsimei | 2017-07-11 00:01:49 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-13 18:27:45 +0200 |
commit | 8f2a177cef73403ec65cac8430b3a0cae0249d37 (patch) | |
tree | 062b5a19380ce17c118e6ab77da2c25acfa17255 | |
parent | d37888ad5f7f3eb7df834e31f4dd11b785f7dc66 (diff) | |
download | scummvm-rg350-8f2a177cef73403ec65cac8430b3a0cae0249d37.tar.gz scummvm-rg350-8f2a177cef73403ec65cac8430b3a0cae0249d37.tar.bz2 scummvm-rg350-8f2a177cef73403ec65cac8430b3a0cae0249d37.zip |
STREAM: add read/write functions for float LE/BE
-rw-r--r-- | common/stream.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/common/stream.h b/common/stream.h index 0ff430f41b..6932c7d2d0 100644 --- a/common/stream.h +++ b/common/stream.h @@ -185,6 +185,32 @@ public: } #endif + + /** + * Write the given 32-bit floating point value stored + * in little endian(LSB first) order into the stream. + */ + FORCEINLINE void writeFloatLE(float value) { + uint32 n; + + memcpy(&n, &value, 4); + + writeUint32LE(n); + } + + + /** + * Write the given 32-bit floating point value stored + * in big endian order into the stream. + */ + FORCEINLINE void writeFloatBE(float value) { + uint32 n; + + memcpy(&n, &value, 4); + + writeUint32BE(n); + } + /** * Write the given string to the stream. * This writes str.size() characters, but no terminating zero byte. @@ -418,6 +444,22 @@ public: } /** + * Read a 32-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 float readFloatBE() { + uint32 n = readUint32BE(); + float f; + + memcpy(&f, &n, 4); + + return f; + } + + /** * Read the specified amount of data into a malloc'ed buffer * which then is wrapped into a MemoryReadStream. * The returned stream might contain less data than requested, |