COMP: split endian.H into foamEndianFwd.H and foamEndian.H
- usually only need big/little defines (which are now in the Fwd) and rarely need byte-swapping. Provide endian.H compatibility include, but foamEndianFwd.H or foamEndian.H to avoid potential name clashes.
This commit is contained in:
parent
98ccb7df6b
commit
546b204793
@ -24,14 +24,16 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-sysInfo
|
||||
|
||||
Description
|
||||
Simple output of endian and system-information
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "profilingSysInfo.H"
|
||||
#include "IOstreams.H"
|
||||
#include "endian.H"
|
||||
#include "foamEndian.H" // For run-time tests
|
||||
#include "cpuInfo.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
11
src/OpenFOAM/compat/endian.H
Normal file
11
src/OpenFOAM/compat/endian.H
Normal file
@ -0,0 +1,11 @@
|
||||
// ************************************************************************* //
|
||||
// Compatibility include
|
||||
|
||||
#ifndef FoamCompat_endian_H
|
||||
#define FoamCompat_endian_H
|
||||
|
||||
#include "foamEndian.H"
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,7 +32,7 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVersion.H"
|
||||
#include "endian.H"
|
||||
#include "foamEndianFwd.H" // For big/little endian defines
|
||||
#include "labelFwd.H"
|
||||
#include "scalarFwd.H"
|
||||
|
||||
|
@ -50,8 +50,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVersion_H
|
||||
#define foamVersion_H
|
||||
#ifndef Foam_foamVersion_H
|
||||
#define Foam_foamVersion_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
@ -23,41 +23,22 @@ License
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Help with architecture-specific aspects.
|
||||
Class
|
||||
Foam::endian
|
||||
|
||||
Defines WM_BIG_ENDIAN or WM_LITTLE_ENDIAN as well as providing a
|
||||
few runtime methods. Primarily used as a namespace, but defined as
|
||||
a class to allow pTraits specialization.
|
||||
Description
|
||||
Help with architecture-specific aspects, primarily used
|
||||
as a namespace, but defined as a class to allow pTraits specialization.
|
||||
|
||||
SourceFiles
|
||||
endianI.H
|
||||
foamEndianI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_endian_H
|
||||
#define Foam_endian_H
|
||||
#ifndef Foam_foamEndian_H
|
||||
#define Foam_foamEndian_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef __BYTE_ORDER__
|
||||
// Clang, Gcc, Icc, Pgi
|
||||
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#define WM_LITTLE_ENDIAN
|
||||
#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
#define WM_BIG_ENDIAN
|
||||
#else
|
||||
#error "__BYTE_ORDER__ is not BIG or LITTLE endian"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Could downgrade to a warning, but then user always needs runtime check.
|
||||
#if !defined(WM_BIG_ENDIAN) && !defined(WM_LITTLE_ENDIAN)
|
||||
#error "Cannot determine BIG or LITTLE endian."
|
||||
#error "Please add to compilation options"
|
||||
#endif
|
||||
#include "foamEndianFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -74,6 +55,15 @@ public:
|
||||
|
||||
// Public Methods
|
||||
|
||||
// FUTURE?
|
||||
// #if defined (WM_BIG_ENDIAN)
|
||||
// //- The endian name as a string
|
||||
// static constexpr const char* name() noexcept { return "MSB"; }
|
||||
// #else
|
||||
// //- The endian name as a string
|
||||
// static constexpr const char* name() noexcept { return "LSB"; }
|
||||
// #endif
|
||||
|
||||
//- Runtime check for big endian.
|
||||
inline static bool isBig() noexcept;
|
||||
|
||||
@ -94,7 +84,7 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "endianI.H"
|
||||
#include "foamEndianI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
71
src/OpenFOAM/primitives/endian/foamEndianFwd.H
Normal file
71
src/OpenFOAM/primitives/endian/foamEndianFwd.H
Normal file
@ -0,0 +1,71 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Define WM_BIG_ENDIAN or WM_LITTLE_ENDIAN
|
||||
and forward declare Foam::endian class.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_foamEndianFwd_H
|
||||
#define Foam_foamEndianFwd_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef __BYTE_ORDER__
|
||||
// Clang, Gcc, Icc, Pgi
|
||||
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#define WM_LITTLE_ENDIAN
|
||||
#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
#define WM_BIG_ENDIAN
|
||||
#else
|
||||
#error "__BYTE_ORDER__ is not BIG or LITTLE endian"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Could downgrade to a warning, but then user always needs runtime check.
|
||||
#if !defined(WM_BIG_ENDIAN) && !defined(WM_LITTLE_ENDIAN)
|
||||
#error "Cannot determine BIG or LITTLE endian."
|
||||
#error "Please add to compilation options"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class endian;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
@ -29,7 +29,7 @@ Description
|
||||
|
||||
#include "Hasher.H"
|
||||
#include "HasherInt.H"
|
||||
#include "endian.H"
|
||||
#include "foamEndianFwd.H" // For big/little endian defines
|
||||
|
||||
// Left-rotate a 32-bit value and carry by nBits
|
||||
#define bitRotateLeft(x, nBits) (((x) << (nBits)) | ((x) >> (32 - (nBits))))
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,8 +37,8 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SHA1.H"
|
||||
#include "endian.H"
|
||||
#include "IOstreams.H"
|
||||
#include "foamEndian.H" // For byte swapping
|
||||
#include <cstring>
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,7 +26,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamGltfObject.H"
|
||||
#include "endian.H"
|
||||
#include "foamEndianFwd.H" // For big/little endian defines
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,7 +26,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkPTraits.H"
|
||||
#include "endian.H"
|
||||
#include "foamEndianFwd.H" // For big/little endian defines
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,7 +27,7 @@ License
|
||||
|
||||
#include "foamVtkLegacyRawFormatter.H"
|
||||
#include "foamVtkOutputOptions.H"
|
||||
#include "endian.H"
|
||||
#include "foamEndian.H" // For byte swapping
|
||||
#include <limits>
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
Loading…
Reference in New Issue
Block a user