X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Ffnetorderstream.cpp;h=2a7191973698a56fcc46f2fbd12c59ff9c63b9d6;hp=9f0e0f056c00eaf3460c72c357c9916d710a4007;hb=f13a8c004b8f182b42d9e4df2bcd7c7f030bf1ad;hpb=9f29c8b32c972db1178d6f8551d5cd57ceb67083 diff --git a/libctsupport/fnetorderstream.cpp b/libctsupport/fnetorderstream.cpp index 9f0e0f0..2a71919 100644 --- a/libctsupport/fnetorderstream.cpp +++ b/libctsupport/fnetorderstream.cpp @@ -1,8 +1,6 @@ /***************************************************************************** ** This is part of the CTSim program -** Copyright (c) 1983-2001 Kevin Rosenberg -** -** $Id: fnetorderstream.cpp,v 1.5 2001/01/28 19:10:18 kevin Exp $ +** Copyright (c) 1983-2009 Kevin Rosenberg ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -30,42 +28,42 @@ #include "fnetorderstream.h" -void +void ConvertNetworkOrder (void* buffer, size_t bytes) { #ifndef WORDS_BIGENDIAN if (bytes < 2) - return; + return; char* start = static_cast(buffer); char* end = start + bytes - 1; // last byte size_t nSwap = bytes / 2; - + while (nSwap-- > 0) { - unsigned char c = *start; - *start++ = *end; - *end-- = c; + unsigned char c = *start; + *start++ = *end; + *end-- = c; } -#endif +#endif } -void +void ConvertReverseNetworkOrder (void* buffer, size_t bytes) { #ifdef WORDS_BIGENDIAN if (bytes < 2) - return; + return; char* start = static_cast(buffer); - char* end = start + bytes - 1; // last byte + char* end = start + bytes - 1; // last byte size_t nSwap = bytes / 2; - + while (nSwap-- > 0) { - unsigned char c = *start; - *start++ = *end; - *end-- = c; + unsigned char c = *start; + *start++ = *end; + *end-- = c; } -#endif +#endif } void @@ -150,7 +148,7 @@ frnetorderstream::writeInt32 (kuint32 n) { write (reinterpret_cast(&n), 4); } -void +void frnetorderstream::writeFloat32 (kfloat32 n) { #ifdef WORDS_BIGENDIAN SwapBytes4 (&n); @@ -158,7 +156,7 @@ frnetorderstream::writeFloat32 (kfloat32 n) { write (reinterpret_cast(&n), 4); } -void +void frnetorderstream::writeFloat64 (kfloat64 n) { #ifdef WORDS_BIGENDIAN SwapBytes8 (&n); @@ -166,7 +164,7 @@ frnetorderstream::writeFloat64 (kfloat64 n) { write (reinterpret_cast(&n), 8); } -void +void frnetorderstream::readInt16 (kuint16& n) { read (reinterpret_cast(&n), 2); #ifdef WORDS_BIGENDIAN @@ -174,7 +172,7 @@ frnetorderstream::readInt16 (kuint16& n) { #endif } -void +void frnetorderstream::readInt32 (kuint32& n) { read (reinterpret_cast(&n), 4); #ifdef WORDS_BIGENDIAN