Cleanup endian support (closes #271)

- Place common code under OSspecific.

By including "endian.H", either one of WM_BIG_ENDIAN or WM_LITTLE_ENDIAN
will be defined.

Provides inline 32-bit and 64-bit byte swap routines that can be
used/re-used elsewhere.

The inplace memory swaps currently used by the VTK output are left for
the moment pending further cleanup of that code.
This commit is contained in:
Mark Olesen
2016-10-17 12:02:01 +02:00
parent ec5eec3a27
commit 2c06a905ab
10 changed files with 304 additions and 161 deletions

View File

@ -24,22 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "writeFuns.H"
#if defined(__mips)
#include <standards.h>
#include <sys/endian.h>
#endif
#if defined(LITTLE_ENDIAN) \
|| defined(_LITTLE_ENDIAN) \
|| defined(__LITTLE_ENDIAN)
#define LITTLEENDIAN 1
#elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
#undef LITTLEENDIAN
#else
#error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
#error "Please add to compilation options"
#endif
#include "endian.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -75,7 +60,7 @@ void Foam::writeFuns::write
{
if (binary)
{
#ifdef LITTLEENDIAN
#ifdef WM_LITTLE_ENDIAN
swapWords(fField.size(), reinterpret_cast<int32_t*>(fField.begin()));
#endif
@ -124,7 +109,7 @@ void Foam::writeFuns::write
{
if (binary)
{
#ifdef LITTLEENDIAN
#ifdef WM_LITTLE_ENDIAN
swapWords
(
(sizeof(label)/4)*elems.size(),