Skip to content

Commit

Permalink
Cleanup|libcore: Byte order terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 9, 2016
1 parent 1a7a83b commit f3e6694
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 212 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/audio/m_mus2midi.cpp
Expand Up @@ -278,7 +278,7 @@ Block M_Mus2Midi(Block const &musData)
<< duint8(0x40);

header = reinterpret_cast<struct mus_header const *>(musData.dataConst());
readPos = musData.dataConst() + littleEndianByteOrder.toNative(header->scoreStart);
readPos = musData.dataConst() + littleEndianByteOrder.toHost(header->scoreStart);
readTime = 0;

// Init channel volumes.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/busyrunner.cpp
Expand Up @@ -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();
}
Expand Down
40 changes: 20 additions & 20 deletions doomsday/apps/client/src/resource/model.cpp
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/libdoomsday/src/filesys/wad.cpp
Expand Up @@ -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));
}
};

Expand All @@ -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.
Expand Down
38 changes: 19 additions & 19 deletions doomsday/apps/libdoomsday/src/filesys/zip.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
}
Expand Down
126 changes: 63 additions & 63 deletions doomsday/sdk/libcore/include/de/data/byteorder.h
@@ -1,7 +1,7 @@
/*
* The Doomsday Engine Project -- libcore
*
* Copyright © 2004-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* Copyright © 2004-2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
Expand All @@ -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</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_BYTEORDER_H
Expand All @@ -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 <typename T>
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 <typename T>
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;
}
};

Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit f3e6694

Please sign in to comment.