From 833ee409041e78f13d0089d3c331d1c75a667e50 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 6 Oct 2020 14:15:51 +0200 Subject: [PATCH] ENH: add pTraits for uint8_t --- applications/test/limits/Test-limits.C | 2 +- src/OpenFOAM/Make/files | 2 + src/OpenFOAM/primitives/Scalar/Scalar.C | 4 +- src/OpenFOAM/primitives/bools/bool/bool.C | 3 +- src/OpenFOAM/primitives/direction/direction.H | 23 ++- .../primitives/direction/directionIO.C | 14 +- src/OpenFOAM/primitives/ints/int16/int16.H | 1 + src/OpenFOAM/primitives/ints/int32/int32.C | 4 +- src/OpenFOAM/primitives/ints/int32/int32.H | 5 +- src/OpenFOAM/primitives/ints/int32/int32IO.C | 18 +- src/OpenFOAM/primitives/ints/int64/int64.C | 4 +- src/OpenFOAM/primitives/ints/int64/int64.H | 5 +- src/OpenFOAM/primitives/ints/int64/int64IO.C | 18 +- src/OpenFOAM/primitives/ints/uint/uint.H | 2 + src/OpenFOAM/primitives/ints/uint16/uint16.H | 1 + src/OpenFOAM/primitives/ints/uint32/uint32.C | 4 +- src/OpenFOAM/primitives/ints/uint32/uint32.H | 5 +- .../primitives/ints/uint32/uint32IO.C | 18 +- src/OpenFOAM/primitives/ints/uint64/uint64.C | 4 +- src/OpenFOAM/primitives/ints/uint64/uint64.H | 5 +- .../primitives/ints/uint64/uint64IO.C | 18 +- src/OpenFOAM/primitives/ints/uint8/uint8.C | 54 ++++++ src/OpenFOAM/primitives/ints/uint8/uint8.H | 159 ++++++++++++++++++ src/OpenFOAM/primitives/ints/uint8/uint8IO.C | 44 +++++ 24 files changed, 347 insertions(+), 70 deletions(-) create mode 100644 src/OpenFOAM/primitives/ints/uint8/uint8.C create mode 100644 src/OpenFOAM/primitives/ints/uint8/uint8.H create mode 100644 src/OpenFOAM/primitives/ints/uint8/uint8IO.C diff --git a/applications/test/limits/Test-limits.C b/applications/test/limits/Test-limits.C index 0f06dc3a8f..73f0dfcb27 100644 --- a/applications/test/limits/Test-limits.C +++ b/applications/test/limits/Test-limits.C @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) { //NONE Info<<"int16:" << pTraits::max << nl; Info<< "=max=" << nl; - Info<< "uint8:" << std::numeric_limits::max() << nl; + Info<< "uint8:" << pTraits::max << nl; Info<< "int16:" << std::numeric_limits::max() << nl; Info<< "int32:" << pTraits::max << nl; Info<< "uint32:" << pTraits::max << nl; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 828c0587d5..5706312424 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -37,6 +37,8 @@ $(chars)/wchar/wcharIO.C primitives/direction/directionIO.C ints = primitives/ints +$(ints)/uint8/uint8.C +$(ints)/uint8/uint8IO.C $(ints)/uint16/uint16.C $(ints)/uint32/uint32.C $(ints)/uint32/uint32IO.C diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.C b/src/OpenFOAM/primitives/Scalar/Scalar.C index de9b00875e..c276674d1c 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.C +++ b/src/OpenFOAM/primitives/Scalar/Scalar.C @@ -34,6 +34,8 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // const char* const pTraits::typeName = "scalar"; +const char* const pTraits::componentNames[] = { "" }; + const Scalar pTraits::zero = 0.0; const Scalar pTraits::one = 1.0; const Scalar pTraits::min = -ScalarVGREAT; @@ -42,8 +44,6 @@ const Scalar pTraits::rootMin = -ScalarROOTVGREAT; const Scalar pTraits::rootMax = ScalarROOTVGREAT; const Scalar pTraits::vsmall = ScalarVSMALL; -const char* const pTraits::componentNames[] = { "" }; - pTraits::pTraits(const Scalar& val) : diff --git a/src/OpenFOAM/primitives/bools/bool/bool.C b/src/OpenFOAM/primitives/bools/bool/bool.C index 378173fc08..63da1e6a4f 100644 --- a/src/OpenFOAM/primitives/bools/bool/bool.C +++ b/src/OpenFOAM/primitives/bools/bool/bool.C @@ -34,10 +34,11 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // const char* const Foam::pTraits::typeName = "bool"; +const char* const Foam::pTraits::componentNames[] = { "" }; + const bool Foam::pTraits::zero = false; const bool Foam::pTraits::one = true; -const char* const Foam::pTraits::componentNames[] = { "" }; Foam::pTraits::pTraits(const bool& p) : diff --git a/src/OpenFOAM/primitives/direction/direction.H b/src/OpenFOAM/primitives/direction/direction.H index 7602a4d7e8..2e3ec46de1 100644 --- a/src/OpenFOAM/primitives/direction/direction.H +++ b/src/OpenFOAM/primitives/direction/direction.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,13 +28,16 @@ Primitive direction Description - Direction is an 8-bit unsigned integer type used to represent the Cartesian - directions etc. + Direction is an 8-bit unsigned integer type used to represent + Cartesian directions, components etc. + +Note + If a different typedef is used, "uint8.H" must be modified accordingly. \*---------------------------------------------------------------------------*/ -#ifndef direction_H -#define direction_H +#ifndef primitives_direction_H +#define primitives_direction_H #include #include @@ -43,6 +47,7 @@ Description namespace Foam { +// Forward Declarations class Istream; class Ostream; @@ -50,10 +55,14 @@ class Ostream; typedef uint8_t direction; +//- Read direction (uint8_t) from stream. direction readDirection(Istream& is); -Istream& operator>>(Istream& is, direction& d); -Ostream& operator<<(Ostream& os, const direction d); -std::ostream& operator<<(std::ostream& os, const direction d); + +Istream& operator>>(Istream& is, direction& val); +Ostream& operator<<(Ostream& os, const direction val); + +std::ostream& operator<<(std::ostream& os, const direction val); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/direction/directionIO.C b/src/OpenFOAM/primitives/direction/directionIO.C index 86d60c1236..c17a3b6546 100644 --- a/src/OpenFOAM/primitives/direction/directionIO.C +++ b/src/OpenFOAM/primitives/direction/directionIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,7 +40,7 @@ Foam::direction Foam::readDirection(Istream& is) } -Foam::Istream& Foam::operator>>(Istream& is, direction& d) +Foam::Istream& Foam::operator>>(Istream& is, direction& val) { token t(is); @@ -55,7 +55,7 @@ Foam::Istream& Foam::operator>>(Istream& is, direction& d) if (t.isLabel()) { - d = direction(t.labelToken()); + val = direction(t.labelToken()); } else { @@ -72,17 +72,17 @@ Foam::Istream& Foam::operator>>(Istream& is, direction& d) } -Foam::Ostream& Foam::operator<<(Ostream& os, const direction d) +Foam::Ostream& Foam::operator<<(Ostream& os, const direction val) { - os.write(label(d)); + os.write(label(val)); os.check(FUNCTION_NAME); return os; } -std::ostream& Foam::operator<<(std::ostream& os, const direction d) +std::ostream& Foam::operator<<(std::ostream& os, const direction val) { - os << int(d); + os << int(val); return os; } diff --git a/src/OpenFOAM/primitives/ints/int16/int16.H b/src/OpenFOAM/primitives/ints/int16/int16.H index 6b3327534f..8ea19f1537 100644 --- a/src/OpenFOAM/primitives/ints/int16/int16.H +++ b/src/OpenFOAM/primitives/ints/int16/int16.H @@ -45,6 +45,7 @@ SourceFiles namespace Foam { +// Forward Declarations class Istream; class Ostream; diff --git a/src/OpenFOAM/primitives/ints/int32/int32.C b/src/OpenFOAM/primitives/ints/int32/int32.C index 67a222c907..2b10a9596d 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32.C +++ b/src/OpenFOAM/primitives/ints/int32/int32.C @@ -30,6 +30,8 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +const char* const Foam::pTraits::componentNames[] = { "" }; + const int32_t Foam::pTraits::zero = 0; const int32_t Foam::pTraits::one = 1; const int32_t Foam::pTraits::min = INT32_MIN; @@ -37,8 +39,6 @@ const int32_t Foam::pTraits::max = INT32_MAX; const int32_t Foam::pTraits::rootMin = pTraits::min; const int32_t Foam::pTraits::rootMax = pTraits::max; -const char* const Foam::pTraits::componentNames[] = { "" }; - Foam::pTraits::pTraits(const int32_t& val) : p_(val) diff --git a/src/OpenFOAM/primitives/ints/int32/int32.H b/src/OpenFOAM/primitives/ints/int32/int32.H index a54d279369..2cf170baf6 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32.H +++ b/src/OpenFOAM/primitives/ints/int32/int32.H @@ -43,15 +43,16 @@ SourceFiles #include #include -#include "word.H" -#include "pTraits.H" #include "direction.H" +#include "pTraits.H" +#include "word.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward Declarations class Istream; class Ostream; diff --git a/src/OpenFOAM/primitives/ints/int32/int32IO.C b/src/OpenFOAM/primitives/ints/int32/int32IO.C index ee8f161844..6ff287a12f 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32IO.C +++ b/src/OpenFOAM/primitives/ints/int32/int32IO.C @@ -78,6 +78,15 @@ bool Foam::readInt32(const char* buf, int32_t& val) } +int32_t Foam::readInt32(Istream& is) +{ + int32_t val(0); + is >> val; + + return val; +} + + Foam::Istream& Foam::operator>>(Istream& is, int32_t& val) { token t(is); @@ -138,15 +147,6 @@ Foam::Istream& Foam::operator>>(Istream& is, int32_t& val) } -int32_t Foam::readInt32(Istream& is) -{ - int32_t val(0); - is >> val; - - return val; -} - - Foam::Ostream& Foam::operator<<(Ostream& os, const int32_t val) { os.write(label(val)); diff --git a/src/OpenFOAM/primitives/ints/int64/int64.C b/src/OpenFOAM/primitives/ints/int64/int64.C index 4a66759f60..c9b7099026 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64.C +++ b/src/OpenFOAM/primitives/ints/int64/int64.C @@ -30,6 +30,8 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +const char* const Foam::pTraits::componentNames[] = { "" }; + const int64_t Foam::pTraits::zero = 0; const int64_t Foam::pTraits::one = 1; const int64_t Foam::pTraits::min = INT64_MIN; @@ -37,8 +39,6 @@ const int64_t Foam::pTraits::max = INT64_MAX; const int64_t Foam::pTraits::rootMin = pTraits::min; const int64_t Foam::pTraits::rootMax = pTraits::max; -const char* const Foam::pTraits::componentNames[] = { "" }; - Foam::pTraits::pTraits(const int64_t& val) : p_(val) diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H index 68a74269f4..0f9faf2757 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64.H +++ b/src/OpenFOAM/primitives/ints/int64/int64.H @@ -43,15 +43,16 @@ SourceFiles #include #include -#include "word.H" -#include "pTraits.H" #include "direction.H" +#include "pTraits.H" +#include "word.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward Declarations class Istream; class Ostream; diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C index 63a807f19b..8ffc448b7e 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64IO.C +++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C @@ -78,6 +78,15 @@ bool Foam::readInt64(const char* buf, int64_t& val) } +int64_t Foam::readInt64(Istream& is) +{ + int64_t val(0); + is >> val; + + return val; +} + + Foam::Istream& Foam::operator>>(Istream& is, int64_t& val) { token t(is); @@ -138,15 +147,6 @@ Foam::Istream& Foam::operator>>(Istream& is, int64_t& val) } -int64_t Foam::readInt64(Istream& is) -{ - int64_t val(0); - is >> val; - - return val; -} - - Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t val) { os.write(label(val)); diff --git a/src/OpenFOAM/primitives/ints/uint/uint.H b/src/OpenFOAM/primitives/ints/uint/uint.H index 3493273484..df5fe5d302 100644 --- a/src/OpenFOAM/primitives/ints/uint/uint.H +++ b/src/OpenFOAM/primitives/ints/uint/uint.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +38,7 @@ SourceFiles #ifndef uint_H #define uint_H +#include "uint8.H" #include "uint16.H" #include "uint32.H" #include "uint64.H" diff --git a/src/OpenFOAM/primitives/ints/uint16/uint16.H b/src/OpenFOAM/primitives/ints/uint16/uint16.H index 7b7a46c622..c61d37e822 100644 --- a/src/OpenFOAM/primitives/ints/uint16/uint16.H +++ b/src/OpenFOAM/primitives/ints/uint16/uint16.H @@ -45,6 +45,7 @@ SourceFiles namespace Foam { +// Forward Declarations class Istream; class Ostream; diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.C b/src/OpenFOAM/primitives/ints/uint32/uint32.C index 05b0fbbea0..340ab250eb 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32.C +++ b/src/OpenFOAM/primitives/ints/uint32/uint32.C @@ -30,6 +30,8 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +const char* const Foam::pTraits::componentNames[] = { "" }; + const uint32_t Foam::pTraits::zero = 0; const uint32_t Foam::pTraits::one = 1; const uint32_t Foam::pTraits::min = 0; @@ -37,8 +39,6 @@ const uint32_t Foam::pTraits::max = UINT32_MAX; const uint32_t Foam::pTraits::rootMin = 0; const uint32_t Foam::pTraits::rootMax = pTraits::max; -const char* const Foam::pTraits::componentNames[] = { "" }; - Foam::pTraits::pTraits(const uint32_t& val) : p_(val) diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.H b/src/OpenFOAM/primitives/ints/uint32/uint32.H index e8458d880d..69e7cb70b9 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32.H +++ b/src/OpenFOAM/primitives/ints/uint32/uint32.H @@ -43,15 +43,16 @@ SourceFiles #include #include -#include "word.H" -#include "pTraits.H" #include "direction.H" +#include "pTraits.H" +#include "word.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward Declarations class Istream; class Ostream; diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C index c4aa308e76..91e47b0312 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C +++ b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C @@ -77,6 +77,15 @@ bool Foam::readUint32(const char* buf, uint32_t& val) } +uint32_t Foam::readUint32(Istream& is) +{ + uint32_t val(0); + is >> val; + + return val; +} + + Foam::Istream& Foam::operator>>(Istream& is, uint32_t& val) { token t(is); @@ -137,15 +146,6 @@ Foam::Istream& Foam::operator>>(Istream& is, uint32_t& val) } -uint32_t Foam::readUint32(Istream& is) -{ - uint32_t val(0); - is >> val; - - return val; -} - - Foam::Ostream& Foam::operator<<(Ostream& os, const uint32_t val) { os.write(label(val)); diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.C b/src/OpenFOAM/primitives/ints/uint64/uint64.C index 989c52a291..804b86ac69 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64.C @@ -30,6 +30,8 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +const char* const Foam::pTraits::componentNames[] = { "" }; + const uint64_t Foam::pTraits::zero = 0; const uint64_t Foam::pTraits::one = 1; const uint64_t Foam::pTraits::min = 0; @@ -37,8 +39,6 @@ const uint64_t Foam::pTraits::max = UINT64_MAX; const uint64_t Foam::pTraits::rootMin = 0; const uint64_t Foam::pTraits::rootMax = pTraits::max; -const char* const Foam::pTraits::componentNames[] = { "" }; - Foam::pTraits::pTraits(const uint64_t& val) : p_(val) diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H index 491d84cd30..cc7624f805 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64.H +++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H @@ -43,15 +43,16 @@ SourceFiles #include #include -#include "word.H" -#include "pTraits.H" #include "direction.H" +#include "pTraits.H" +#include "word.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward Declarations class Istream; class Ostream; diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C index 46766b20bc..0643b18923 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C @@ -77,6 +77,15 @@ bool Foam::readUint64(const char* buf, uint64_t& val) } +uint64_t Foam::readUint64(Istream& is) +{ + uint64_t val(0); + is >> val; + + return val; +} + + Foam::Istream& Foam::operator>>(Istream& is, uint64_t& val) { token t(is); @@ -137,15 +146,6 @@ Foam::Istream& Foam::operator>>(Istream& is, uint64_t& val) } -uint64_t Foam::readUint64(Istream& is) -{ - uint64_t val(0); - is >> val; - - return val; -} - - Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t val) { os.write(label(val)); diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8.C b/src/OpenFOAM/primitives/ints/uint8/uint8.C new file mode 100644 index 0000000000..0c9cdf74bd --- /dev/null +++ b/src/OpenFOAM/primitives/ints/uint8/uint8.C @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 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 . + +\*---------------------------------------------------------------------------*/ + +#include "uint8.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +const char* const Foam::pTraits::typeName = "uint8"; +const char* const Foam::pTraits::componentNames[] = { "" }; + +const uint8_t Foam::pTraits::zero = 0; +const uint8_t Foam::pTraits::one = 1; +const uint8_t Foam::pTraits::min = 0; +const uint8_t Foam::pTraits::max = UINT8_MAX; +const uint8_t Foam::pTraits::rootMin = 0; +const uint8_t Foam::pTraits::rootMax = UINT8_MAX; + + +Foam::pTraits::pTraits(const uint8_t& val) +: + p_(val) +{} + +Foam::pTraits::pTraits(Istream& is) +{ + is >> p_; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8.H b/src/OpenFOAM/primitives/ints/uint8/uint8.H new file mode 100644 index 0000000000..85d412c21d --- /dev/null +++ b/src/OpenFOAM/primitives/ints/uint8/uint8.H @@ -0,0 +1,159 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 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 . + +Primitive + uint8_t + +Description + 8bit unsigned integer + +SourceFiles + uint8.C + uint8IO.C + +\*---------------------------------------------------------------------------*/ + +#ifndef primitives_uint8_H +#define primitives_uint8_H + +#include +#include +#include + +#include "direction.H" +#include "pTraits.H" +#include "word.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward Declarations +class Istream; +class Ostream; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- A word representation of uint8 value +inline word name(const uint8_t val) +{ + return word(std::to_string(int(val)), false); // Needs no stripping +} + + +//- A word representation of uint8 value +template<> +struct nameOp +{ + inline word operator()(const uint8_t val) const + { + return word(std::to_string(int(val)), false); // Needs no stripping + } +}; + + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +//- Read uint8_t from stream. +uint8_t readUint8(Istream& is); + +// IO operators are identical to direction, which is uint8_t + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Template specialization for pTraits +template<> +class pTraits +{ + uint8_t p_; + +public: + + // Typedefs + + //- Component type + typedef uint8_t cmptType; + + + // Member Constants + + //- Dimensionality of space + static constexpr direction dim = 3; + + //- Rank of uint8_t is 0 + static constexpr direction rank = 0; + + //- Number of components in uint8_t is 1 + static constexpr direction nComponents = 1; + + + // Static Data Members + + static const char* const typeName; + static const char* const componentNames[]; + static const uint8_t zero; + static const uint8_t one; + static const uint8_t min; + static const uint8_t max; + static const uint8_t rootMax; + static const uint8_t rootMin; + + + // Constructors + + //- Copy construct from primitive + explicit pTraits(const uint8_t& val); + + //- Read construct from Istream + explicit pTraits(Istream& is); + + + // Member Functions + + //- Access to the value + operator uint8_t() const + { + return p_; + } + + //- Access to the value + operator uint8_t&() + { + return p_; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8IO.C b/src/OpenFOAM/primitives/ints/uint8/uint8IO.C new file mode 100644 index 0000000000..b81239fe15 --- /dev/null +++ b/src/OpenFOAM/primitives/ints/uint8/uint8IO.C @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 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 . + +\*---------------------------------------------------------------------------*/ + +#include "uint8.H" +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +uint8_t Foam::readUint8(Istream& is) +{ + uint8_t val(0); + is >> val; + + return val; +} + +// IO operators are identical to direction, which is uint8_t + + +// ************************************************************************* //