From f3e6694cd4e24aef4ec0e245ef7eed46656d2303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Sat, 9 Jul 2016 10:41:25 +0300 Subject: [PATCH] Cleanup|libcore: Byte order terminology --- doomsday/apps/client/src/audio/m_mus2midi.cpp | 2 +- doomsday/apps/client/src/busyrunner.cpp | 4 +- doomsday/apps/client/src/resource/model.cpp | 40 ++--- doomsday/apps/libdoomsday/src/filesys/wad.cpp | 8 +- doomsday/apps/libdoomsday/src/filesys/zip.cpp | 38 ++-- .../sdk/libcore/include/de/data/byteorder.h | 126 +++++++------- doomsday/sdk/libcore/src/c_wrapper.cpp | 32 ++-- doomsday/sdk/libcore/src/data/byteorder.cpp | 162 +++++++++--------- doomsday/sdk/libcore/src/data/reader.cpp | 6 +- doomsday/sdk/libcore/src/data/writer.cpp | 6 +- 10 files changed, 212 insertions(+), 212 deletions(-) diff --git a/doomsday/apps/client/src/audio/m_mus2midi.cpp b/doomsday/apps/client/src/audio/m_mus2midi.cpp index c060d4834a..bae72c21ba 100644 --- a/doomsday/apps/client/src/audio/m_mus2midi.cpp +++ b/doomsday/apps/client/src/audio/m_mus2midi.cpp @@ -278,7 +278,7 @@ Block M_Mus2Midi(Block const &musData) << duint8(0x40); header = reinterpret_cast(musData.dataConst()); - readPos = musData.dataConst() + littleEndianByteOrder.toNative(header->scoreStart); + readPos = musData.dataConst() + littleEndianByteOrder.toHost(header->scoreStart); readTime = 0; // Init channel volumes. diff --git a/doomsday/apps/client/src/busyrunner.cpp b/doomsday/apps/client/src/busyrunner.cpp index b678aa55f2..05a47ace16 100644 --- a/doomsday/apps/client/src/busyrunner.cpp +++ b/doomsday/apps/client/src/busyrunner.cpp @@ -279,8 +279,8 @@ void BusyMode_FreezeGameForBusyMode(void) { // This is only possible from the main thread. if (ClientWindow::mainExists() && - DoomsdayApp::app().busyMode().taskRunner() && - de::App::inMainThread()) + DoomsdayApp::app().busyMode().taskRunner() && + de::App::inMainThread()) { ClientWindow::main().busy().renderTransitionFrame(); } diff --git a/doomsday/apps/client/src/resource/model.cpp b/doomsday/apps/client/src/resource/model.cpp index 63abf1bcc5..d65fc7eac8 100644 --- a/doomsday/apps/client/src/resource/model.cpp +++ b/doomsday/apps/client/src/resource/model.cpp @@ -80,23 +80,23 @@ static bool readMd2Header(FileHandle &file, md2_header_t &hdr) size_t readBytes = file.read((uint8_t *)&hdr, sizeof(md2_header_t)); if(readBytes < sizeof(md2_header_t)) return false; - hdr.magic = littleEndianByteOrder.toNative(hdr.magic); - hdr.version = littleEndianByteOrder.toNative(hdr.version); - hdr.skinWidth = littleEndianByteOrder.toNative(hdr.skinWidth); - hdr.skinHeight = littleEndianByteOrder.toNative(hdr.skinHeight); - hdr.frameSize = littleEndianByteOrder.toNative(hdr.frameSize); - hdr.numSkins = littleEndianByteOrder.toNative(hdr.numSkins); - hdr.numVertices = littleEndianByteOrder.toNative(hdr.numVertices); - hdr.numTexCoords = littleEndianByteOrder.toNative(hdr.numTexCoords); - hdr.numTriangles = littleEndianByteOrder.toNative(hdr.numTriangles); - hdr.numGlCommands = littleEndianByteOrder.toNative(hdr.numGlCommands); - hdr.numFrames = littleEndianByteOrder.toNative(hdr.numFrames); - hdr.offsetSkins = littleEndianByteOrder.toNative(hdr.offsetSkins); - hdr.offsetTexCoords = littleEndianByteOrder.toNative(hdr.offsetTexCoords); - hdr.offsetTriangles = littleEndianByteOrder.toNative(hdr.offsetTriangles); - hdr.offsetFrames = littleEndianByteOrder.toNative(hdr.offsetFrames); - hdr.offsetGlCommands = littleEndianByteOrder.toNative(hdr.offsetGlCommands); - hdr.offsetEnd = littleEndianByteOrder.toNative(hdr.offsetEnd); + hdr.magic = littleEndianByteOrder.toHost(hdr.magic); + hdr.version = littleEndianByteOrder.toHost(hdr.version); + hdr.skinWidth = littleEndianByteOrder.toHost(hdr.skinWidth); + hdr.skinHeight = littleEndianByteOrder.toHost(hdr.skinHeight); + hdr.frameSize = littleEndianByteOrder.toHost(hdr.frameSize); + hdr.numSkins = littleEndianByteOrder.toHost(hdr.numSkins); + hdr.numVertices = littleEndianByteOrder.toHost(hdr.numVertices); + hdr.numTexCoords = littleEndianByteOrder.toHost(hdr.numTexCoords); + hdr.numTriangles = littleEndianByteOrder.toHost(hdr.numTriangles); + hdr.numGlCommands = littleEndianByteOrder.toHost(hdr.numGlCommands); + hdr.numFrames = littleEndianByteOrder.toHost(hdr.numFrames); + hdr.offsetSkins = littleEndianByteOrder.toHost(hdr.offsetSkins); + hdr.offsetTexCoords = littleEndianByteOrder.toHost(hdr.offsetTexCoords); + hdr.offsetTriangles = littleEndianByteOrder.toHost(hdr.offsetTriangles); + hdr.offsetFrames = littleEndianByteOrder.toHost(hdr.offsetFrames); + hdr.offsetGlCommands = littleEndianByteOrder.toHost(hdr.offsetGlCommands); + hdr.offsetEnd = littleEndianByteOrder.toHost(hdr.offsetEnd); return true; } @@ -117,9 +117,9 @@ static bool readHeaderDmd(FileHandle &file, dmd_header_t &hdr) size_t readBytes = file.read((uint8_t *)&hdr, sizeof(dmd_header_t)); if(readBytes < sizeof(dmd_header_t)) return false; - hdr.magic = littleEndianByteOrder.toNative(hdr.magic); - hdr.version = littleEndianByteOrder.toNative(hdr.version); - hdr.flags = littleEndianByteOrder.toNative(hdr.flags); + hdr.magic = littleEndianByteOrder.toHost(hdr.magic); + hdr.version = littleEndianByteOrder.toHost(hdr.version); + hdr.flags = littleEndianByteOrder.toHost(hdr.flags); return true; } diff --git a/doomsday/apps/libdoomsday/src/filesys/wad.cpp b/doomsday/apps/libdoomsday/src/filesys/wad.cpp index 2e771056c5..caabd8d6fa 100644 --- a/doomsday/apps/libdoomsday/src/filesys/wad.cpp +++ b/doomsday/apps/libdoomsday/src/filesys/wad.cpp @@ -48,8 +48,8 @@ struct FileHeader if (readBytes != 12) throw ReadError("FileHeader::operator << (FileHandle &)", "Source file is truncated"); identification = Block(buf, 4); - lumpRecordsCount = littleEndianByteOrder.toNative(*(dint32 *)(buf + 4)); - lumpRecordsOffset = littleEndianByteOrder.toNative(*(dint32 *)(buf + 8)); + lumpRecordsCount = littleEndianByteOrder.toHost(*(dint32 *)(buf + 4)); + lumpRecordsOffset = littleEndianByteOrder.toHost(*(dint32 *)(buf + 8)); } }; @@ -68,8 +68,8 @@ struct IndexEntry if (readBytes != 16) throw ReadError("IndexEntry::operator << (FileHandle &)", "Source file is truncated"); name = Block(buf + 8, 8); - offset = littleEndianByteOrder.toNative(*(dint32 *)(buf)); - size = littleEndianByteOrder.toNative(*(dint32 *)(buf + 4)); + offset = littleEndianByteOrder.toHost(*(dint32 *)(buf)); + size = littleEndianByteOrder.toHost(*(dint32 *)(buf + 4)); } /// Perform all translations and encodings to the actual lump name. diff --git a/doomsday/apps/libdoomsday/src/filesys/zip.cpp b/doomsday/apps/libdoomsday/src/filesys/zip.cpp index 95b077312a..c47acdc6b0 100644 --- a/doomsday/apps/libdoomsday/src/filesys/zip.cpp +++ b/doomsday/apps/libdoomsday/src/filesys/zip.cpp @@ -136,17 +136,17 @@ static bool readArchiveHeader(FileHandle &file, localfileheader_t &hdr) file.seek(initPos, SeekSet); if (!(readBytes < sizeof(localfileheader_t))) { - hdr.signature = littleEndianByteOrder.toNative(hdr.signature); - hdr.requiredVersion = littleEndianByteOrder.toNative(hdr.requiredVersion); - hdr.flags = littleEndianByteOrder.toNative(hdr.flags); - hdr.compression = littleEndianByteOrder.toNative(hdr.compression); - hdr.lastModTime = littleEndianByteOrder.toNative(hdr.lastModTime); - hdr.lastModDate = littleEndianByteOrder.toNative(hdr.lastModDate); - hdr.crc32 = littleEndianByteOrder.toNative(hdr.crc32); - hdr.compressedSize = littleEndianByteOrder.toNative(hdr.compressedSize); - hdr.size = littleEndianByteOrder.toNative(hdr.size); - hdr.fileNameSize = littleEndianByteOrder.toNative(hdr.fileNameSize); - hdr.extraFieldSize = littleEndianByteOrder.toNative(hdr.extraFieldSize); + hdr.signature = littleEndianByteOrder.toHost(hdr.signature); + hdr.requiredVersion = littleEndianByteOrder.toHost(hdr.requiredVersion); + hdr.flags = littleEndianByteOrder.toHost(hdr.flags); + hdr.compression = littleEndianByteOrder.toHost(hdr.compression); + hdr.lastModTime = littleEndianByteOrder.toHost(hdr.lastModTime); + hdr.lastModDate = littleEndianByteOrder.toHost(hdr.lastModDate); + hdr.crc32 = littleEndianByteOrder.toHost(hdr.crc32); + hdr.compressedSize = littleEndianByteOrder.toHost(hdr.compressedSize); + hdr.size = littleEndianByteOrder.toHost(hdr.size); + hdr.fileNameSize = littleEndianByteOrder.toHost(hdr.fileNameSize); + hdr.extraFieldSize = littleEndianByteOrder.toHost(hdr.extraFieldSize); return true; } return false; @@ -168,13 +168,13 @@ static bool readCentralEnd(FileHandle &file, centralend_t &end) size_t readBytes = file.read((uint8_t *)&end, sizeof(centralend_t)); if (!(readBytes < sizeof(centralend_t))) { - end.disk = littleEndianByteOrder.toNative(end.disk); - end.centralStartDisk= littleEndianByteOrder.toNative(end.centralStartDisk); - end.diskEntryCount = littleEndianByteOrder.toNative(end.diskEntryCount); - end.totalEntryCount = littleEndianByteOrder.toNative(end.totalEntryCount); - end.size = littleEndianByteOrder.toNative(end.size); - end.offset = littleEndianByteOrder.toNative(end.offset); - end.commentSize = littleEndianByteOrder.toNative(end.commentSize); + end.disk = littleEndianByteOrder.toHost(end.disk); + end.centralStartDisk= littleEndianByteOrder.toHost(end.centralStartDisk); + end.diskEntryCount = littleEndianByteOrder.toHost(end.diskEntryCount); + end.totalEntryCount = littleEndianByteOrder.toHost(end.totalEntryCount); + end.size = littleEndianByteOrder.toHost(end.size); + end.offset = littleEndianByteOrder.toHost(end.offset); + end.commentSize = littleEndianByteOrder.toHost(end.commentSize); return true; } return false; @@ -378,7 +378,7 @@ Zip::Zip(FileHandle &hndl, String path, FileInfo const &info, File1 *container) // Is this the signature? handle_->read((uint8_t *)&signature, sizeof(signature)); - if (littleEndianByteOrder.toNative(signature) == SIG_END_OF_CENTRAL_DIR) + if (littleEndianByteOrder.toHost(signature) == SIG_END_OF_CENTRAL_DIR) { foundCentralDirectory = true; // Yes, this is it. } diff --git a/doomsday/sdk/libcore/include/de/data/byteorder.h b/doomsday/sdk/libcore/include/de/data/byteorder.h index d70ec3b18e..1087642371 100644 --- a/doomsday/sdk/libcore/include/de/data/byteorder.h +++ b/doomsday/sdk/libcore/include/de/data/byteorder.h @@ -1,7 +1,7 @@ /* * The Doomsday Engine Project -- libcore * - * Copyright © 2004-2013 Jaakko Keränen + * Copyright © 2004-2016 Jaakko Keränen * * @par License * LGPL: http://www.gnu.org/licenses/lgpl.html @@ -14,7 +14,7 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. You should have received a copy of * the GNU Lesser General Public License along with this program; if not, see: - * http://www.gnu.org/licenses + * http://www.gnu.org/licenses */ #ifndef LIBDENG2_BYTEORDER_H @@ -35,80 +35,80 @@ class DENG2_PUBLIC ByteOrder virtual ~ByteOrder() {} /** - * Converts a 16-bit unsigned integer from foreign byte order to the native one. + * Converts a 16-bit unsigned integer from network byte order to the host order. * - * @param foreignValue Value in foreign byte order. - * @param nativeValue Value in the host's native byte order. + * @param networkValue Value in network byte order. + * @param hostValue Value in the host's host byte order. */ - virtual void foreignToNative(duint16 const &foreignValue, duint16 &nativeValue) const = 0; + virtual void networkToHost(duint16 const &networkValue, duint16 &hostValue) const = 0; /** - * Converts a 32-bit unsigned integer from foreign byte order to the native one. + * Converts a 32-bit unsigned integer from network byte order to the host order. * - * @param foreignValue Value in foreign byte order. - * @param nativeValue Value in the host's native byte order. + * @param networkValue Value in network byte order. + * @param hostValue Value in the host's host byte order. */ - virtual void foreignToNative(duint32 const &foreignValue, duint32 &nativeValue) const = 0; + virtual void networkToHost(duint32 const &networkValue, duint32 &hostValue) const = 0; /** - * Converts a 64-bit unsigned integer from foreign byte order to the native one. + * Converts a 64-bit unsigned integer from network byte order to the host order. * - * @param foreignValue Value in foreign byte order. - * @param nativeValue Value in the host's native byte order. + * @param networkValue Value in network byte order. + * @param hostValue Value in the host's host byte order. */ - virtual void foreignToNative(duint64 const &foreignValue, duint64 &nativeValue) const = 0; + virtual void networkToHost(duint64 const &networkValue, duint64 &hostValue) const = 0; /** - * Converts a 16-bit unsigned integer from native byte order to the foreign one. + * Converts a 16-bit unsigned integer from host byte order to the network order. * - * @param nativeValue Value in the host's native byte order. - * @param foreignValue Value in foreign byte order is written here. + * @param hostValue Value in the host's host byte order. + * @param networkValue Value in network byte order is written here. */ - virtual void nativeToForeign(duint16 const &nativeValue, duint16 &foreignValue) const = 0; + virtual void hostToNetwork(duint16 const &hostValue, duint16 &networkValue) const = 0; /** - * Converts a 32-bit unsigned integer from native byte order to the foreign one. + * Converts a 32-bit unsigned integer from host byte order to the network order. * - * @param nativeValue Value in the host's native byte order. - * @param foreignValue Value in foreign byte order is written here. + * @param hostValue Value in the host's host byte order. + * @param networkValue Value in network byte order is written here. */ - virtual void nativeToForeign(duint32 const &nativeValue, duint32 &foreignValue) const = 0; + virtual void hostToNetwork(duint32 const &hostValue, duint32 &networkValue) const = 0; /** - * Converts a 64-bit unsigned integer from native byte order to the foreign one. + * Converts a 64-bit unsigned integer from host byte order to the network order. * - * @param nativeValue Value in the host's native byte order. - * @param foreignValue Value in foreign byte order is written here. + * @param hostValue Value in the host's host byte order. + * @param networkValue Value in network byte order is written here. */ - virtual void nativeToForeign(duint64 const &nativeValue, duint64 &foreignValue) const = 0; + virtual void hostToNetwork(duint64 const &hostValue, duint64 &networkValue) const = 0; // The signed variants. - void nativeToForeign(dint16 const &nativeValue, dint16 &foreignValue) const; - void nativeToForeign(dint32 const &nativeValue, dint32 &foreignValue) const; - void nativeToForeign(dint64 const &nativeValue, dint64 &foreignValue) const; - void foreignToNative(dint16 const &foreignValue, dint16 &nativeValue) const; - void foreignToNative(dint32 const &foreignValue, dint32 &nativeValue) const; - void foreignToNative(dint64 const &foreignValue, dint64 &nativeValue) const; + void hostToNetwork(dint16 const &hostValue, dint16 &networkValue) const; + void hostToNetwork(dint32 const &hostValue, dint32 &networkValue) const; + void hostToNetwork(dint64 const &hostValue, dint64 &networkValue) const; + void networkToHost(dint16 const &networkValue, dint16 &hostValue) const; + void networkToHost(dint32 const &networkValue, dint32 &hostValue) const; + void networkToHost(dint64 const &networkValue, dint64 &hostValue) const; // Floating point. - void nativeToForeign(dfloat const &nativeValue, dfloat &foreignValue) const; - void nativeToForeign(ddouble const &nativeValue, ddouble &foreignValue) const; - void foreignToNative(dfloat const &foreignValue, dfloat &nativeValue) const; - void foreignToNative(ddouble const &foreignValue, ddouble &nativeValue) const; + void hostToNetwork(dfloat const &hostValue, dfloat &networkValue) const; + void hostToNetwork(ddouble const &hostValue, ddouble &networkValue) const; + void networkToHost(dfloat const &networkValue, dfloat &hostValue) const; + void networkToHost(ddouble const &networkValue, ddouble &hostValue) const; // Convenience. template - T toForeign(T const &nativeValue) const { - T foreignValue; - nativeToForeign(nativeValue, foreignValue); - return foreignValue; + T toNetwork(T const &hostValue) const { + T networkValue; + hostToNetwork(hostValue, networkValue); + return networkValue; } template - T toNative(T const &foreignValue) const { - T nativeValue; - foreignToNative(foreignValue, nativeValue); - return nativeValue; + T toHost(T const &networkValue) const { + T hostValue; + networkToHost(networkValue, hostValue); + return hostValue; } }; @@ -120,15 +120,15 @@ class DENG2_PUBLIC ByteOrder class DENG2_PUBLIC BigEndianByteOrder : public ByteOrder { public: - using ByteOrder::foreignToNative; - using ByteOrder::nativeToForeign; - - void foreignToNative(duint16 const &foreignValue, duint16 &nativeValue) const; - void foreignToNative(duint32 const &foreignValue, duint32 &nativeValue) const; - void foreignToNative(duint64 const &foreignValue, duint64 &nativeValue) const; - void nativeToForeign(duint16 const &nativeValue, duint16 &foreignValue) const; - void nativeToForeign(duint32 const &nativeValue, duint32 &foreignValue) const; - void nativeToForeign(duint64 const &nativeValue, duint64 &foreignValue) const; + using ByteOrder::networkToHost; + using ByteOrder::hostToNetwork; + + void networkToHost(duint16 const &networkValue, duint16 &hostValue) const; + void networkToHost(duint32 const &networkValue, duint32 &hostValue) const; + void networkToHost(duint64 const &networkValue, duint64 &hostValue) const; + void hostToNetwork(duint16 const &hostValue, duint16 &networkValue) const; + void hostToNetwork(duint32 const &hostValue, duint32 &networkValue) const; + void hostToNetwork(duint64 const &hostValue, duint64 &networkValue) const; }; /// Network byte order is big endian. @@ -142,20 +142,20 @@ typedef BigEndianByteOrder NetworkByteOrder; class DENG2_PUBLIC LittleEndianByteOrder : public ByteOrder { public: - using ByteOrder::foreignToNative; - using ByteOrder::nativeToForeign; - - void foreignToNative(duint16 const &foreignValue, duint16 &nativeValue) const; - void foreignToNative(duint32 const &foreignValue, duint32 &nativeValue) const; - void foreignToNative(duint64 const &foreignValue, duint64 &nativeValue) const; - void nativeToForeign(duint16 const &nativeValue, duint16 &foreignValue) const; - void nativeToForeign(duint32 const &nativeValue, duint32 &foreignValue) const; - void nativeToForeign(duint64 const &nativeValue, duint64 &foreignValue) const; + using ByteOrder::networkToHost; + using ByteOrder::hostToNetwork; + + void networkToHost(duint16 const &networkValue, duint16 &hostValue) const; + void networkToHost(duint32 const &networkValue, duint32 &hostValue) const; + void networkToHost(duint64 const &networkValue, duint64 &hostValue) const; + void hostToNetwork(duint16 const &hostValue, duint16 &networkValue) const; + void hostToNetwork(duint32 const &hostValue, duint32 &networkValue) const; + void hostToNetwork(duint64 const &hostValue, duint64 &networkValue) const; }; // Swaps the bytes of a 16-bit unsigned integer. inline duint16 swap16(duint16 const &n) { - return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); + return duint16((n & 0xff) << 8) | duint16((n & 0xff00) >> 8); } /// Swaps the bytes of a 32-bit unsigned integer. diff --git a/doomsday/sdk/libcore/src/c_wrapper.cpp b/doomsday/sdk/libcore/src/c_wrapper.cpp index 709f3f1d85..aa029ba00f 100644 --- a/doomsday/sdk/libcore/src/c_wrapper.cpp +++ b/doomsday/sdk/libcore/src/c_wrapper.cpp @@ -300,95 +300,95 @@ int UnixInfo_GetConfigValue(char const *configFile, char const *key, char *dest, dint16 LittleEndianByteOrder_ToForeignInt16(dint16 value) { DENG2_ASSERT(sizeof(dint16) == sizeof(de::dint16)); - return de::littleEndianByteOrder.toForeign(de::dint16(value)); + return de::littleEndianByteOrder.toNetwork(de::dint16(value)); } dint32 LittleEndianByteOrder_ToForeignInt32(dint32 value) { DENG2_ASSERT(sizeof(dint32) == sizeof(de::dint32)); - return de::littleEndianByteOrder.toForeign(de::dint32(value)); + return de::littleEndianByteOrder.toNetwork(de::dint32(value)); } dint64 LittleEndianByteOrder_ToForeignInt64(dint64 value) { DENG2_ASSERT(sizeof(dint64) == sizeof(de::dint64)); - return de::littleEndianByteOrder.toForeign(de::dint64(value)); + return de::littleEndianByteOrder.toNetwork(de::dint64(value)); } duint16 LittleEndianByteOrder_ToForeignUInt16(duint16 value) { DENG2_ASSERT(sizeof(duint16) == sizeof(de::duint16)); - return de::littleEndianByteOrder.toForeign(de::duint16(value)); + return de::littleEndianByteOrder.toNetwork(de::duint16(value)); } duint32 LittleEndianByteOrder_ToForeignUInt32(duint32 value) { DENG2_ASSERT(sizeof(duint32) == sizeof(de::duint32)); - return de::littleEndianByteOrder.toForeign(de::duint32(value)); + return de::littleEndianByteOrder.toNetwork(de::duint32(value)); } duint64 LittleEndianByteOrder_ToForeignUInt64(duint64 value) { DENG2_ASSERT(sizeof(duint64) == sizeof(de::duint64)); - return de::littleEndianByteOrder.toForeign(de::duint64(value)); + return de::littleEndianByteOrder.toNetwork(de::duint64(value)); } dfloat LittleEndianByteOrder_ToForeignFloat(dfloat value) { DENG2_ASSERT(sizeof(dfloat) == sizeof(de::dfloat)); - return de::littleEndianByteOrder.toForeign(de::dfloat(value)); + return de::littleEndianByteOrder.toNetwork(de::dfloat(value)); } ddouble LittleEndianByteOrder_ToForeignDouble(ddouble value) { DENG2_ASSERT(sizeof(ddouble) == sizeof(de::ddouble)); - return de::littleEndianByteOrder.toForeign(de::ddouble(value)); + return de::littleEndianByteOrder.toNetwork(de::ddouble(value)); } dint16 LittleEndianByteOrder_ToNativeInt16(dint16 value) { DENG2_ASSERT(sizeof(dint16) == sizeof(de::dint16)); - return de::littleEndianByteOrder.toNative(de::dint16(value)); + return de::littleEndianByteOrder.toHost(de::dint16(value)); } dint32 LittleEndianByteOrder_ToNativeInt32(dint32 value) { DENG2_ASSERT(sizeof(dint32) == sizeof(de::dint32)); - return de::littleEndianByteOrder.toNative(de::dint32(value)); + return de::littleEndianByteOrder.toHost(de::dint32(value)); } dint64 LittleEndianByteOrder_ToNativeInt64(dint64 value) { DENG2_ASSERT(sizeof(dint64) == sizeof(de::dint64)); - return de::littleEndianByteOrder.toNative(de::dint64(value)); + return de::littleEndianByteOrder.toHost(de::dint64(value)); } duint16 LittleEndianByteOrder_ToNativeUInt16(duint16 value) { DENG2_ASSERT(sizeof(duint16) == sizeof(de::duint16)); - return de::littleEndianByteOrder.toNative(de::duint16(value)); + return de::littleEndianByteOrder.toHost(de::duint16(value)); } duint32 LittleEndianByteOrder_ToNativeUInt32(duint32 value) { DENG2_ASSERT(sizeof(duint32) == sizeof(de::duint32)); - return de::littleEndianByteOrder.toNative(de::duint32(value)); + return de::littleEndianByteOrder.toHost(de::duint32(value)); } duint64 LittleEndianByteOrder_ToNativeUInt64(duint64 value) { DENG2_ASSERT(sizeof(duint64) == sizeof(de::duint64)); - return de::littleEndianByteOrder.toNative(de::duint64(value)); + return de::littleEndianByteOrder.toHost(de::duint64(value)); } dfloat LittleEndianByteOrder_ToNativeFloat(dfloat value) { DENG2_ASSERT(sizeof(dfloat) == sizeof(de::dfloat)); - return de::littleEndianByteOrder.toNative(de::dfloat(value)); + return de::littleEndianByteOrder.toHost(de::dfloat(value)); } ddouble LittleEndianByteOrder_ToNativeDouble(ddouble value) { DENG2_ASSERT(sizeof(ddouble) == sizeof(de::ddouble)); - return de::littleEndianByteOrder.toNative(de::ddouble(value)); + return de::littleEndianByteOrder.toHost(de::ddouble(value)); } diff --git a/doomsday/sdk/libcore/src/data/byteorder.cpp b/doomsday/sdk/libcore/src/data/byteorder.cpp index 0e8b041778..a14b225b53 100644 --- a/doomsday/sdk/libcore/src/data/byteorder.cpp +++ b/doomsday/sdk/libcore/src/data/byteorder.cpp @@ -14,7 +14,7 @@ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. You should have received a copy of * the GNU Lesser General Public License along with this program; if not, see: - * http://www.gnu.org/licenses + * http://www.gnu.org/licenses */ #include "de/data/byteorder.h" @@ -26,175 +26,175 @@ using de::LittleEndianByteOrder; DENG2_PUBLIC BigEndianByteOrder de::bigEndianByteOrder; DENG2_PUBLIC LittleEndianByteOrder de::littleEndianByteOrder; -void ByteOrder::nativeToForeign(de::dint16 const &nativeValue, de::dint16 &foreignValue) const +void ByteOrder::hostToNetwork(de::dint16 const &hostValue, de::dint16 &networkValue) const { - nativeToForeign(reinterpret_cast(nativeValue), - reinterpret_cast< de::duint16 &>(foreignValue)); + hostToNetwork(reinterpret_cast(hostValue), + reinterpret_cast< de::duint16 &>(networkValue)); } -void ByteOrder::nativeToForeign(de::dint32 const &nativeValue, de::dint32 &foreignValue) const +void ByteOrder::hostToNetwork(de::dint32 const &hostValue, de::dint32 &networkValue) const { - nativeToForeign(reinterpret_cast(nativeValue), - reinterpret_cast< de::duint32 &>(foreignValue)); + hostToNetwork(reinterpret_cast(hostValue), + reinterpret_cast< de::duint32 &>(networkValue)); } -void ByteOrder::nativeToForeign(de::dint64 const &nativeValue, de::dint64 &foreignValue) const +void ByteOrder::hostToNetwork(de::dint64 const &hostValue, de::dint64 &networkValue) const { - nativeToForeign(reinterpret_cast(nativeValue), - reinterpret_cast< de::duint64 &>(foreignValue)); + hostToNetwork(reinterpret_cast(hostValue), + reinterpret_cast< de::duint64 &>(networkValue)); } -void ByteOrder::foreignToNative(de::dint16 const &foreignValue, de::dint16 &nativeValue) const +void ByteOrder::networkToHost(de::dint16 const &networkValue, de::dint16 &hostValue) const { - foreignToNative(reinterpret_cast(foreignValue), - reinterpret_cast< de::duint16 &>(nativeValue)); + networkToHost(reinterpret_cast(networkValue), + reinterpret_cast< de::duint16 &>(hostValue)); } -void ByteOrder::foreignToNative(de::dint32 const &foreignValue, de::dint32 &nativeValue) const +void ByteOrder::networkToHost(de::dint32 const &networkValue, de::dint32 &hostValue) const { - foreignToNative(reinterpret_cast(foreignValue), - reinterpret_cast< de::duint32 &>(nativeValue)); + networkToHost(reinterpret_cast(networkValue), + reinterpret_cast< de::duint32 &>(hostValue)); } -void ByteOrder::foreignToNative(de::dint64 const &foreignValue, de::dint64 &nativeValue) const +void ByteOrder::networkToHost(de::dint64 const &networkValue, de::dint64 &hostValue) const { - foreignToNative(reinterpret_cast(foreignValue), - reinterpret_cast< de::duint64 &>(nativeValue)); + networkToHost(reinterpret_cast(networkValue), + reinterpret_cast< de::duint64 &>(hostValue)); } -void ByteOrder::nativeToForeign(de::dfloat const &nativeValue, de::dfloat &foreignValue) const +void ByteOrder::hostToNetwork(de::dfloat const &hostValue, de::dfloat &networkValue) const { DENG2_ASSERT(sizeof(de::dfloat) == sizeof(de::duint32)); - nativeToForeign(reinterpret_cast(nativeValue), - reinterpret_cast< de::duint32 &>(foreignValue)); + hostToNetwork(reinterpret_cast(hostValue), + reinterpret_cast< de::duint32 &>(networkValue)); } -void ByteOrder::nativeToForeign(de::ddouble const &nativeValue, de::ddouble &foreignValue) const +void ByteOrder::hostToNetwork(de::ddouble const &hostValue, de::ddouble &networkValue) const { DENG2_ASSERT(sizeof(de::ddouble) == sizeof(de::duint64)); - nativeToForeign(reinterpret_cast(nativeValue), - reinterpret_cast< de::duint64 &>(foreignValue)); + hostToNetwork(reinterpret_cast(hostValue), + reinterpret_cast< de::duint64 &>(networkValue)); } -void ByteOrder::foreignToNative(de::dfloat const &foreignValue, de::dfloat &nativeValue) const +void ByteOrder::networkToHost(de::dfloat const &networkValue, de::dfloat &hostValue) const { DENG2_ASSERT(sizeof(de::dfloat) == sizeof(de::duint32)); - foreignToNative(reinterpret_cast(foreignValue), - reinterpret_cast< de::duint32 &>(nativeValue)); + networkToHost(reinterpret_cast(networkValue), + reinterpret_cast< de::duint32 &>(hostValue)); } -void ByteOrder::foreignToNative(de::ddouble const &foreignValue, de::ddouble &nativeValue) const +void ByteOrder::networkToHost(de::ddouble const &networkValue, de::ddouble &hostValue) const { DENG2_ASSERT(sizeof(de::ddouble) == sizeof(de::duint64)); - foreignToNative(reinterpret_cast(foreignValue), - reinterpret_cast< de::duint64 &>(nativeValue)); + networkToHost(reinterpret_cast(networkValue), + reinterpret_cast< de::duint64 &>(hostValue)); } -void BigEndianByteOrder::foreignToNative(de::duint16 const &foreignValue, de::duint16 &nativeValue) const +void BigEndianByteOrder::networkToHost(de::duint16 const &networkValue, de::duint16 &hostValue) const { -#ifdef __BIG_ENDIAN__ - nativeValue = foreignValue; +#ifdef __BIG_ENDIAN__ + hostValue = networkValue; #else - nativeValue = swap16(foreignValue); + hostValue = swap16(networkValue); #endif } -void BigEndianByteOrder::foreignToNative(de::duint32 const &foreignValue, de::duint32 &nativeValue) const +void BigEndianByteOrder::networkToHost(de::duint32 const &networkValue, de::duint32 &hostValue) const { -#ifdef __BIG_ENDIAN__ - nativeValue = foreignValue; +#ifdef __BIG_ENDIAN__ + hostValue = networkValue; #else - nativeValue = swap32(foreignValue); + hostValue = swap32(networkValue); #endif } -void BigEndianByteOrder::foreignToNative(de::duint64 const &foreignValue, de::duint64 &nativeValue) const +void BigEndianByteOrder::networkToHost(de::duint64 const &networkValue, de::duint64 &hostValue) const { -#ifdef __BIG_ENDIAN__ - nativeValue = foreignValue; +#ifdef __BIG_ENDIAN__ + hostValue = networkValue; #else - nativeValue = swap64(foreignValue); + hostValue = swap64(networkValue); #endif } -void BigEndianByteOrder::nativeToForeign(de::duint16 const &nativeValue, de::duint16 &foreignValue) const +void BigEndianByteOrder::hostToNetwork(de::duint16 const &hostValue, de::duint16 &networkValue) const { -#ifdef __BIG_ENDIAN__ - foreignValue = nativeValue; +#ifdef __BIG_ENDIAN__ + networkValue = hostValue; #else - foreignValue = swap16(nativeValue); + networkValue = swap16(hostValue); #endif } -void BigEndianByteOrder::nativeToForeign(de::duint32 const &nativeValue, de::duint32 &foreignValue) const +void BigEndianByteOrder::hostToNetwork(de::duint32 const &hostValue, de::duint32 &networkValue) const { -#ifdef __BIG_ENDIAN__ - foreignValue = nativeValue; +#ifdef __BIG_ENDIAN__ + networkValue = hostValue; #else - foreignValue = swap32(nativeValue); + networkValue = swap32(hostValue); #endif } -void BigEndianByteOrder::nativeToForeign(de::duint64 const &nativeValue, de::duint64 &foreignValue) const +void BigEndianByteOrder::hostToNetwork(de::duint64 const &hostValue, de::duint64 &networkValue) const { -#ifdef __BIG_ENDIAN__ - foreignValue = nativeValue; +#ifdef __BIG_ENDIAN__ + networkValue = hostValue; #else - foreignValue = swap64(nativeValue); + networkValue = swap64(hostValue); #endif } -void LittleEndianByteOrder::foreignToNative(de::duint16 const &foreignValue, de::duint16 &nativeValue) const +void LittleEndianByteOrder::networkToHost(de::duint16 const &networkValue, de::duint16 &hostValue) const { -#ifndef __BIG_ENDIAN__ - nativeValue = foreignValue; +#ifndef __BIG_ENDIAN__ + hostValue = networkValue; #else - nativeValue = swap16(foreignValue); + hostValue = swap16(networkValue); #endif } -void LittleEndianByteOrder::foreignToNative(de::duint32 const &foreignValue, de::duint32 &nativeValue) const +void LittleEndianByteOrder::networkToHost(de::duint32 const &networkValue, de::duint32 &hostValue) const { -#ifndef __BIG_ENDIAN__ - nativeValue = foreignValue; +#ifndef __BIG_ENDIAN__ + hostValue = networkValue; #else - nativeValue = swap32(foreignValue); + hostValue = swap32(networkValue); #endif } -void LittleEndianByteOrder::foreignToNative(de::duint64 const &foreignValue, de::duint64 &nativeValue) const +void LittleEndianByteOrder::networkToHost(de::duint64 const &networkValue, de::duint64 &hostValue) const { -#ifndef __BIG_ENDIAN__ - nativeValue = foreignValue; +#ifndef __BIG_ENDIAN__ + hostValue = networkValue; #else - nativeValue = swap64(foreignValue); + hostValue = swap64(networkValue); #endif } -void LittleEndianByteOrder::nativeToForeign(de::duint16 const &nativeValue, de::duint16 &foreignValue) const +void LittleEndianByteOrder::hostToNetwork(de::duint16 const &hostValue, de::duint16 &networkValue) const { -#ifndef __BIG_ENDIAN__ - foreignValue = nativeValue; +#ifndef __BIG_ENDIAN__ + networkValue = hostValue; #else - foreignValue = swap16(nativeValue); + networkValue = swap16(hostValue); #endif } -void LittleEndianByteOrder::nativeToForeign(de::duint32 const &nativeValue, de::duint32 &foreignValue) const +void LittleEndianByteOrder::hostToNetwork(de::duint32 const &hostValue, de::duint32 &networkValue) const { -#ifndef __BIG_ENDIAN__ - foreignValue = nativeValue; +#ifndef __BIG_ENDIAN__ + networkValue = hostValue; #else - foreignValue = swap32(nativeValue); + networkValue = swap32(hostValue); #endif } -void LittleEndianByteOrder::nativeToForeign(de::duint64 const &nativeValue, de::duint64 &foreignValue) const +void LittleEndianByteOrder::hostToNetwork(de::duint64 const &hostValue, de::duint64 &networkValue) const { -#ifndef __BIG_ENDIAN__ - foreignValue = nativeValue; +#ifndef __BIG_ENDIAN__ + networkValue = hostValue; #else - foreignValue = swap64(nativeValue); + networkValue = swap64(hostValue); #endif } @@ -203,7 +203,7 @@ de::duint64 de::swap64(de::duint64 const &n) de::duint64 result; dbyte const *in = reinterpret_cast(&n); dbyte *out = reinterpret_cast(&result); - + out[0] = in[7]; out[1] = in[6]; out[2] = in[5]; @@ -212,6 +212,6 @@ de::duint64 de::swap64(de::duint64 const &n) out[5] = in[2]; out[6] = in[1]; out[7] = in[0]; - + return result; } diff --git a/doomsday/sdk/libcore/src/data/reader.cpp b/doomsday/sdk/libcore/src/data/reader.cpp index 88d08d368e..a27dd297a5 100644 --- a/doomsday/sdk/libcore/src/data/reader.cpp +++ b/doomsday/sdk/libcore/src/data/reader.cpp @@ -267,7 +267,7 @@ Reader &Reader::operator >> (dint16 &word) Reader &Reader::operator >> (duint16 &word) { d->readBytes(reinterpret_cast(&word), 2); - d->convert.foreignToNative(word, word); + d->convert.networkToHost(word, word); return *this; } @@ -279,7 +279,7 @@ Reader &Reader::operator >> (dint32 &dword) Reader &Reader::operator >> (duint32 &dword) { d->readBytes(reinterpret_cast(&dword), 4); - d->convert.foreignToNative(dword, dword); + d->convert.networkToHost(dword, dword); return *this; } @@ -291,7 +291,7 @@ Reader &Reader::operator >> (dint64 &qword) Reader &Reader::operator >> (duint64 &qword) { d->readBytes(reinterpret_cast(&qword), 8); - d->convert.foreignToNative(qword, qword); + d->convert.networkToHost(qword, qword); return *this; } diff --git a/doomsday/sdk/libcore/src/data/writer.cpp b/doomsday/sdk/libcore/src/data/writer.cpp index 1c84c4547a..11155a6326 100644 --- a/doomsday/sdk/libcore/src/data/writer.cpp +++ b/doomsday/sdk/libcore/src/data/writer.cpp @@ -138,7 +138,7 @@ Writer &Writer::operator << (dint16 const &word) Writer &Writer::operator << (duint16 const &word) { duint16 netWord; - d->convert.nativeToForeign(word, netWord); + d->convert.hostToNetwork(word, netWord); d->write(reinterpret_cast(&netWord), 2); return *this; } @@ -151,7 +151,7 @@ Writer &Writer::operator << (dint32 const &dword) Writer &Writer::operator << (duint32 const &dword) { duint32 netDword; - d->convert.nativeToForeign(dword, netDword); + d->convert.hostToNetwork(dword, netDword); d->write(reinterpret_cast(&netDword), 4); return *this; } @@ -164,7 +164,7 @@ Writer &Writer::operator << (dint64 const &qword) Writer &Writer::operator << (duint64 const &qword) { duint64 netQword; - d->convert.nativeToForeign(qword, netQword); + d->convert.hostToNetwork(qword, netQword); d->write(reinterpret_cast(&netQword), 8); return *this; }