diff --git a/applications/test/compoundToken1/Make/files b/applications/test/compoundToken1/Make/files index b0f090a63a..9eeea09195 100644 --- a/applications/test/compoundToken1/Make/files +++ b/applications/test/compoundToken1/Make/files @@ -1,3 +1,3 @@ -Test-compoundToken1.C +Test-compoundToken1.cxx EXE = $(FOAM_USER_APPBIN)/Test-compoundToken1 diff --git a/applications/test/compoundToken1/Test-compoundToken1.C b/applications/test/compoundToken1/Test-compoundToken1.cxx similarity index 98% rename from applications/test/compoundToken1/Test-compoundToken1.C rename to applications/test/compoundToken1/Test-compoundToken1.cxx index 6a27793aae..12976b13eb 100644 --- a/applications/test/compoundToken1/Test-compoundToken1.C +++ b/applications/test/compoundToken1/Test-compoundToken1.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2023 OpenCFD Ltd. + Copyright (C) 2023-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -158,7 +158,8 @@ void populateCompound(token::compound& ct, const dictionary& dict) } break; - case token::tokenType::LABEL : + case token::tokenType::INTEGER_32 : + case token::tokenType::INTEGER_64 : { fillComponents(label, cmpts, 123); } diff --git a/applications/test/token/Test-token.cxx b/applications/test/token/Test-token.cxx index 7fda54b642..0971708f70 100644 --- a/applications/test/token/Test-token.cxx +++ b/applications/test/token/Test-token.cxx @@ -43,6 +43,29 @@ Description using namespace Foam; +const char yesno[2] = { 'n', 'y' }; + +void printIntegralTest(const token& tok) +{ + Info<< "Test: " << tok.info() << nl + << " is int32 = " << yesno[tok.is_int32()] + << ", int64 = " << yesno[tok.is_int64()] + << ", uint32 = " << yesno[tok.is_uint32()] + << ", uint64 = " << yesno[tok.is_uint64()] + << nl; +} + + +void printFloatTest(const token& tok) +{ + Info<< "Test: " << tok.info() << nl + << " is float = " << yesno[tok.isFloat()] + << ", double = " << yesno[tok.isDouble()] + << ", number = " << yesno[tok.isNumber()] + << nl; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: @@ -56,6 +79,23 @@ int main(int argc, char *argv[]) token tok1; Info<< "default construct: " << tok1.info() << endl; + tok1 = label(100); + Info<< "assign label: " << tok1.info() << endl; + + tok1 = int64_t(100); + Info<< "assign int64: " << tok1.info() << endl; + + tok1 = int32_t(100); + Info<< "assign int32: " << tok1.info() << endl; + + { + tok1.int64Token(int64_t(INT32_MIN)-1); + Info<< "set int64Token: " << tok1.info() << endl; + + printIntegralTest(tok1); + printFloatTest(tok1); + } + tok1 = double(3.14159); Info<< "assign double: " << tok1.info() << endl; diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index 2849b5c2f6..c0420f59a2 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011-2016,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -150,8 +150,17 @@ public: //- Read a string (including enclosing double-quotes) virtual Istream& read(string&) = 0; - //- Read a label - virtual Istream& read(label&) = 0; + //- Read int32_t + virtual Istream& read(int32_t&) = 0; + + //- Read int64_t + virtual Istream& read(int64_t&) = 0; + + //- Read uint32_t + virtual Istream& read(uint32_t&) = 0; + + //- Read uint64_t + virtual Istream& read(uint64_t&) = 0; //- Read a float virtual Istream& read(float&) = 0; diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index 521388b350..beb8687bb1 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011-2016,2024 OpenFOAM Foundation Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -154,6 +154,12 @@ public: //- Write int64_t virtual Ostream& write(const int64_t val) = 0; + //- Write uint32_t + virtual Ostream& write(const uint32_t val) = 0; + + //- Write uint64_t + virtual Ostream& write(const uint64_t val) = 0; + //- Write float virtual Ostream& write(const float val) = 0; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H index 42ecd8f1d6..8568c8bf7c 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2011-2013,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -184,8 +184,17 @@ public: // Read a string virtual Istream& read(string& str) override; - //- Read a label - virtual Istream& read(label& val) override; + //- Read int32_t + virtual Istream& read(int32_t& val) override; + + //- Read int64_t + virtual Istream& read(int64_t& val) override; + + //- Read uint32_t + virtual Istream& read(uint32_t& val) override; + + //- Read uint64_t + virtual Istream& read(uint64_t& val) override; //- Read a float virtual Istream& read(float& val) override; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C index 589e757e2d..6816c36028 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2011-2015,2024 OpenFOAM Foundation + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -306,9 +306,7 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) if (c == token::FLAG) { - char flagVal; - - if (read(flagVal)) + if (char flagVal; read(flagVal)) { processFlags(*this, flagVal); } @@ -349,8 +347,7 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) case token::tokenType::WORD : case token::tokenType::DIRECTIVE : { - word val; - if (readString(val)) + if (word val; readString(val)) { if ( @@ -376,8 +373,7 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) case token::tokenType::VERBATIM : case token::tokenType::CHAR_DATA : { - string val; - if (readString(val)) + if (string val; readString(val)) { t = std::move(val); t.setType(token::tokenType(c)); @@ -389,13 +385,54 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) return *this; } - // Label - case token::tokenType::LABEL : + // (signed) int32 + case token::tokenType::INTEGER_32 : { - label val; - if (read(val)) + if (int32_t val; read(val)) { - t = val; + t.int32Token(val); + } + else + { + t.setBad(); + } + return *this; + } + + // (signed) int64 + case token::tokenType::INTEGER_64 : + { + if (int64_t val; read(val)) + { + t.int64Token(val); + } + else + { + t.setBad(); + } + return *this; + } + + // (unsigned) int32 + case token::tokenType::UNSIGNED_INTEGER_32 : + { + if (uint32_t val; read(val)) + { + t.uint32Token(val); + } + else + { + t.setBad(); + } + return *this; + } + + // (unsigned) int64 + case token::tokenType::UNSIGNED_INTEGER_64 : + { + if (uint64_t val; read(val)) + { + t.uint64Token(val); } else { @@ -407,8 +444,7 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) // Float case token::tokenType::FLOAT : { - float val; - if (read(val)) + if (float val; read(val)) { t = val; } @@ -422,8 +458,7 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) // Double case token::tokenType::DOUBLE : { - double val; - if (read(val)) + if (double val; read(val)) { t = val; } @@ -473,7 +508,28 @@ Foam::Istream& Foam::UIPstreamBase::read(string& str) } -Foam::Istream& Foam::UIPstreamBase::read(label& val) +Foam::Istream& Foam::UIPstreamBase::read(int32_t& val) +{ + readFromBuffer(val); + return *this; +} + + +Foam::Istream& Foam::UIPstreamBase::read(int64_t& val) +{ + readFromBuffer(val); + return *this; +} + + +Foam::Istream& Foam::UIPstreamBase::read(uint32_t& val) +{ + readFromBuffer(val); + return *this; +} + + +Foam::Istream& Foam::UIPstreamBase::read(uint64_t& val) { readFromBuffer(val); return *this; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H index 0dc65315f1..5a0185fd4b 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2014 OpenFOAM Foundation + Copyright (C) 2011-2014,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -192,12 +192,18 @@ public: //- Write string virtual Ostream& write(const std::string& str) override; - //- Write int32_t as a label + //- Write int32_t virtual Ostream& write(const int32_t val) override; - //- Write int64_t as a label + //- Write int64_t virtual Ostream& write(const int64_t val) override; + //- Write uint32_t + virtual Ostream& write(const uint32_t val) override; + + //- Write uint64_t + virtual Ostream& write(const uint64_t val) override; + //- Write float virtual Ostream& write(const float val) override; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C index cc665f0cb6..d1f3f482bf 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2011-2017,2024 OpenFOAM Foundation Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -321,7 +321,7 @@ Foam::Ostream& Foam::UOPstreamBase::write(const std::string& str) Foam::Ostream& Foam::UOPstreamBase::write(const int32_t val) { - putChar(token::tokenType::LABEL); + putChar(token::tokenType::INTEGER_32); writeToBuffer(val); return *this; } @@ -329,7 +329,23 @@ Foam::Ostream& Foam::UOPstreamBase::write(const int32_t val) Foam::Ostream& Foam::UOPstreamBase::write(const int64_t val) { - putChar(token::tokenType::LABEL); + putChar(token::tokenType::INTEGER_64); + writeToBuffer(val); + return *this; +} + + +Foam::Ostream& Foam::UOPstreamBase::write(const uint32_t val) +{ + putChar(token::tokenType::UNSIGNED_INTEGER_32); + writeToBuffer(val); + return *this; +} + + +Foam::Ostream& Foam::UOPstreamBase::write(const uint64_t val) +{ + putChar(token::tokenType::UNSIGNED_INTEGER_64); writeToBuffer(val); return *this; } diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index 7f110596af..a550fff7d1 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -714,7 +714,7 @@ Foam::Istream& Foam::ISstream::read(token& t) case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : { - label labelVal = (c != '.'); // used as bool here + bool isIntegral = (c != '.'); // possible integral value? unsigned nChar = 0; buf[nChar++] = c; @@ -725,7 +725,7 @@ Foam::Istream& Foam::ISstream::read(token& t) ( is_.get(c) && ( - isdigit(c) + std::isdigit(c) || c == '+' || c == '-' || c == '.' @@ -734,10 +734,10 @@ Foam::Istream& Foam::ISstream::read(token& t) ) ) { - if (labelVal) - { - labelVal = isdigit(c); - } + // Silently skip "'" digit separators in numeric literals? + + // Still possible as integral? + isIntegral = isIntegral && std::isdigit(c); buf[nChar++] = c; if (nChar == bufLen) @@ -766,23 +766,91 @@ Foam::Istream& Foam::ISstream::read(token& t) { is_.putback(c); - if (nChar == 1 && buf[0] == '-') + if (nChar == 1) { - // A single '-' is punctuation - t = token::punctuationToken(token::MINUS); - } - else if (labelVal && Foam::read(buf, labelVal)) - { - t = labelVal; - } - else - { - scalar scalarVal; - - if (readScalar(buf, scalarVal)) + // Special single char handling + switch (buf[0]) { - // A scalar or too big to fit as a label - t = scalarVal; + case '-' : // A single '-' is punctuation + { + t.pToken(token::MINUS); + break; + } + case '.' : // A single '.' is currently bad + { + t.setBad(); + break; + } + default : + { + if (isIntegral) + { + // Single digit : conversion is trivial + t.int32Token(buf[0] - '0'); + } + else + { + // At the moment nothing to handle here + t.setBad(); + } + break; + } + } + return *this; + } + + if (isIntegral) + { + // Parse as an integral? + // - read with largest resolution and narrow when possible. + // - retain (signed|unsigned) int32/int64 ... + + if (int64_t val; Foam::readInt64(buf, val)) + { + // Use smaller representations when possible + if (val >= INT32_MIN && val <= INT32_MAX) + { + t.int32Token(static_cast(val)); + } + else if (val >= 0 && val <= int64_t(UINT32_MAX)) + { + t.uint32Token(static_cast(val)); + } + else + { + t.int64Token(val); + } + } + else if (uint64_t val; Foam::readUint64(buf, val)) + { + // Use smaller representations when possible + if (val <= UINT32_MAX) + { + t.uint32Token(static_cast(val)); + } + else + { + t.uint64Token(val); + } + } + else + { + // Fallthrough to scalar parsing + isIntegral = false; + } + } + + // Floating point format or a series of digits that are too + // big to fit an integral representation + // + // - read as 'scalar' (float|double) since this is what the + // rest of the code expects to handle anyhow + + if (!isIntegral) + { + if (scalar val; Foam::readScalar(buf, val)) + { + t = val; } else { @@ -1007,7 +1075,31 @@ Foam::Istream& Foam::ISstream::read(string& str) } -Foam::Istream& Foam::ISstream::read(label& val) +Foam::Istream& Foam::ISstream::read(int32_t& val) +{ + is_ >> val; + syncState(); + return *this; +} + + +Foam::Istream& Foam::ISstream::read(int64_t& val) +{ + is_ >> val; + syncState(); + return *this; +} + + +Foam::Istream& Foam::ISstream::read(uint32_t& val) +{ + is_ >> val; + syncState(); + return *this; +} + + +Foam::Istream& Foam::ISstream::read(uint64_t& val) { is_ >> val; syncState(); diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H index 223784367a..24b8894a1a 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2012 OpenFOAM Foundation + Copyright (C) 2011-2012,2024 OpenFOAM Foundation Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -226,8 +226,17 @@ public: // and an embedded newline character. virtual Istream& read(string& str) override; - //- Read a label - virtual Istream& read(label& val) override; + //- Read int32_t + virtual Istream& read(int32_t& val) override; + + //- Read int64_t + virtual Istream& read(int64_t& val) override; + + //- Read uint32_t + virtual Istream& read(uint32_t& val) override; + + //- Read uint64_t + virtual Istream& read(uint64_t& val) override; //- Read a float virtual Istream& read(float& val) override; diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C index 96267e4cdf..becb16173b 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011-2016,2024 OpenFOAM Foundation Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -218,6 +218,22 @@ Foam::Ostream& Foam::OSstream::write(const int64_t val) } +Foam::Ostream& Foam::OSstream::write(const uint32_t val) +{ + os_ << val; + syncState(); + return *this; +} + + +Foam::Ostream& Foam::OSstream::write(const uint64_t val) +{ + os_ << val; + syncState(); + return *this; +} + + Foam::Ostream& Foam::OSstream::write(const float val) { os_ << val; diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H index 3344fc7739..7fa9546521 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2014 OpenFOAM Foundation + Copyright (C) 2011-2014,2024 OpenFOAM Foundation Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -198,6 +198,12 @@ public: //- Write int64_t virtual Ostream& write(const int64_t val) override; + //- Write uint32_t + virtual Ostream& write(const uint32_t val) override; + + //- Write uint64_t + virtual Ostream& write(const uint64_t val) override; + //- Write float virtual Ostream& write(const float val) override; diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C index c768677d69..9847c8ba7b 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2014 OpenFOAM Foundation + Copyright (C) 2011-2014,2024 OpenFOAM Foundation Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -140,6 +140,20 @@ Foam::Ostream& Foam::prefixOSstream::write(const int64_t val) } +Foam::Ostream& Foam::prefixOSstream::write(const uint32_t val) +{ + checkWritePrefix(); + return OSstream::write(val); +} + + +Foam::Ostream& Foam::prefixOSstream::write(const uint64_t val) +{ + checkWritePrefix(); + return OSstream::write(val); +} + + Foam::Ostream& Foam::prefixOSstream::write(const float val) { checkWritePrefix(); diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H index d69afb0cc4..ebf3087d22 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2014 OpenFOAM Foundation + Copyright (C) 2011-2014,2024 OpenFOAM Foundation Copyright (C) 2020-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -130,6 +130,12 @@ public: //- Write int64_t virtual Ostream& write(const int64_t val) override; + //- Write uint32_t + virtual Ostream& write(const uint32_t val) override; + + //- Write uint64_t + virtual Ostream& write(const uint64_t val) override; + //- Write float virtual Ostream& write(const float val) override; diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 22f0ca99f9..a487f0fe21 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2011-2015,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -643,7 +643,28 @@ Foam::Istream& Foam::ITstream::read(string&) } -Foam::Istream& Foam::ITstream::read(label&) +Foam::Istream& Foam::ITstream::read(int32_t&) +{ + NotImplemented; + return *this; +} + + +Foam::Istream& Foam::ITstream::read(int64_t&) +{ + NotImplemented; + return *this; +} + + +Foam::Istream& Foam::ITstream::read(uint32_t&) +{ + NotImplemented; + return *this; +} + + +Foam::Istream& Foam::ITstream::read(uint64_t&) { NotImplemented; return *this; diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index 454e371df7..cf2e2239bb 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011-2016,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -509,8 +509,17 @@ public: //- triggers not implemented error virtual Istream& read(string&) override; - //- Read a label : triggers not implemented error - virtual Istream& read(label&) override; + //- Read int32_t : triggers not implemented error + virtual Istream& read(int32_t&) override; + + //- Read int64_t : triggers not implemented error + virtual Istream& read(int64_t&) override; + + //- Read uint32_t : triggers not implemented error + virtual Istream& read(uint32_t&) override; + + //- Read uint64_t : triggers not implemented error + virtual Istream& read(uint64_t&) override; //- Read a float : triggers not implemented error virtual Istream& read(float&) override; diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C index 7f984710ea..dd0aa65f87 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,7 +65,7 @@ Foam::Ostream& Foam::OTstream::writeQuoted if (quoted) { // tokenType::STRING - tokens().emplace_back() = string(str, len); + tokens().emplace_back() = Foam::string(str, len); } else if (len > 0) { @@ -120,7 +120,7 @@ Foam::Ostream& Foam::OTstream::write(const std::string& str) Foam::Ostream& Foam::OTstream::write(const int32_t val) { - tokens().push_back(token(label(val))); // tokenType::LABEL + tokens().emplace_back().int32Token(val); return *this; } @@ -128,24 +128,36 @@ Foam::Ostream& Foam::OTstream::write(const int32_t val) Foam::Ostream& Foam::OTstream::write(const int64_t val) { - tokens().push_back(token(label(val))); // tokenType::LABEL + tokens().emplace_back().int64Token(val); + return *this; +} + +Foam::Ostream& Foam::OTstream::write(const uint32_t val) +{ + tokens().emplace_back().uint32Token(val); + + return *this; +} + + +Foam::Ostream& Foam::OTstream::write(const uint64_t val) +{ + tokens().emplace_back().uint64Token(val); return *this; } Foam::Ostream& Foam::OTstream::write(const float val) { - tokens().push_back(token(val)); // tokenType::FLOAT - + tokens().emplace_back().floatToken(val); return *this; } Foam::Ostream& Foam::OTstream::write(const double val) { - tokens().push_back(token(val)); // tokenType::DOUBLE - + tokens().emplace_back().doubleToken(val); return *this; } diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H index 7af4253e98..731f72c17d 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2024 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -137,12 +137,18 @@ public: //- Write string virtual Ostream& write(const std::string& str) override; - //- Write int32_t as a label + //- Write int32_t virtual Ostream& write(const int32_t val) override; - //- Write int64_t as a label + //- Write int64_t virtual Ostream& write(const int64_t val) override; + //- Write uint32_t + virtual Ostream& write(const uint32_t val) override; + + //- Write uint64_t + virtual Ostream& write(const uint64_t val) override; + //- Write float virtual Ostream& write(const float val) override; diff --git a/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H b/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H index 1a95bf351d..b681772209 100644 --- a/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H +++ b/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H @@ -128,8 +128,29 @@ public: return *this; } - //- Read a label - virtual Istream& read(label&) override + //- Read int32_t + virtual Istream& read(int32_t&) override + { + NotImplemented; + return *this; + } + + //- Read int64_t + virtual Istream& read(int64_t&) override + { + NotImplemented; + return *this; + } + + //- Read uint32_t + virtual Istream& read(uint32_t&) override + { + NotImplemented; + return *this; + } + + //- Read uint64_t + virtual Istream& read(uint64_t&) override { NotImplemented; return *this; diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index bebff97161..45b5361f41 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011-2016,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -30,6 +30,10 @@ Class Description A token holds an item read from Istream. +Note + Use boolean() static method for creating a \b bool token + since \c bool and \c int are otherwise indistinguishable + SourceFiles tokenI.H token.C @@ -84,7 +88,10 @@ public: FLAG, //!< stream flag (1-byte bitmask) PUNCTUATION, //!< single character punctuation BOOL, //!< boolean type - LABEL, //!< label (integer) type + INTEGER_32, //!< int32 type + INTEGER_64, //!< int64 type + UNSIGNED_INTEGER_32, //!< uint32 type + UNSIGNED_INTEGER_64, //!< uint64 type FLOAT, //!< float (single-precision) type DOUBLE, //!< double (double-precision) type @@ -107,7 +114,13 @@ public: // Aliases FLOAT_SCALAR = FLOAT, //!< compatibility name for FLOAT DOUBLE_SCALAR = DOUBLE, //!< compatibility name for DOUBLE - VERBATIMSTRING = VERBATIM //!< compatibility name for VERBATIM + VERBATIMSTRING = VERBATIM, //!< compatibility name for VERBATIM + + #if (WM_LABEL_SIZE == 64) + LABEL = INTEGER_64, //!< compatibility name + #else + LABEL = INTEGER_32, //!< compatibility name + #endif }; @@ -463,10 +476,11 @@ private: // Fundamental values. Largest first for any {} initialization. int64_t int64Val; int32_t int32Val; + uint64_t uint64Val; + uint32_t uint32Val; int flagVal; // bitmask - stored as int, not enum punctuationToken punctuationVal; - label labelVal; float floatVal; double doubleVal; @@ -495,12 +509,23 @@ private: //- Set as UNDEFINED and zero the union content without any checking inline void setUndefined() noexcept; - //- True if token type corresponds to WORD or WORD-variant. + //- Token type corresponds to (int32, uint32, ...) + inline static bool is_integerToken(tokenType tokType) noexcept; + + //- Token type corresponds to WORD or WORD-variant. inline static bool is_wordToken(tokenType tokType) noexcept; - //- True if token type corresponds to STRING or STRING-variant + //- Token type corresponds to STRING or STRING-variant inline static bool is_stringToken(tokenType tokType) noexcept; + //- Return integral type or emit parseError + template + inline Type getIntegral(const char* expected) const; + + //- Return integral/floating-point type or emit parseError + template + inline Type getArithmetic(const char* expected) const; + // Parse error, expected 'expected', found ... void parseError(const char* expected) const; @@ -527,16 +552,23 @@ public: //- Construct punctuation character token inline explicit token(punctuationToken p, label lineNum=0) noexcept; - //- Construct label token - //- \note Use boolean() static method for creating a \b bool token - //- since \c bool and \c int are otherwise indistinguishable - inline explicit token(const label val, label lineNum=0) noexcept; + //- Construct 32-bit integer token + inline explicit token(int32_t val, label lineNum=0) noexcept; + + //- Construct 64-bit integer token + inline explicit token(int64_t val, label lineNum=0) noexcept; + + //- Construct unsigned 32-bit integer token + inline explicit token(uint32_t val, label lineNum=0) noexcept; + + //- Construct unsigned 64-bit integer token + inline explicit token(uint64_t val, label lineNum=0) noexcept; //- Construct float token - inline explicit token(const float val, label lineNum=0) noexcept; + inline explicit token(float val, label lineNum=0) noexcept; //- Construct double token - inline explicit token(const double val, label lineNum=0) noexcept; + inline explicit token(double val, label lineNum=0) noexcept; //- Copy construct word token inline explicit token(const word& w, label lineNum=0); @@ -640,15 +672,33 @@ public: inline bool isPunctuation() const noexcept; //- True if token is PUNCTUATION and equal to parameter - inline bool isPunctuation(const punctuationToken p) const noexcept; + inline bool isPunctuation(punctuationToken p) const noexcept; //- Token is PUNCTUATION and isseparator inline bool isSeparator() const noexcept; - //- Token is LABEL + //- Token is (int32 | int64 | uint32 | uint64) + inline bool isIntType() const noexcept; + + //- Token is INTEGER_32 or is convertible to one + inline bool is_int32() const noexcept; + + //- Token is INTEGER_64 or is convertible to one + inline bool is_int64() const noexcept; + + //- Token is UNSIGNED_INTEGER_32 or is convertible to one + inline bool is_uint32() const noexcept; + + //- Token is UNSIGNED_INTEGER_64 or is convertible to one + inline bool is_uint64() const noexcept; + + //- Integral token is convertible to Foam::label inline bool isLabel() const noexcept; - //- True if token is LABEL and equal to parameter + //- Integral token is convertible to Foam::uLabel + inline bool isULabel() const noexcept; + + //- True if token is integer type and equal to parameter inline bool isLabel(const label value) const noexcept; //- Token is FLOAT @@ -660,7 +710,7 @@ public: //- Token is FLOAT or DOUBLE inline bool isScalar() const noexcept; - //- Token is LABEL, FLOAT or DOUBLE + //- Token is (signed/unsigned) integer type, FLOAT or DOUBLE inline bool isNumber() const noexcept; //- Token is word-variant (WORD, DIRECTIVE) @@ -729,23 +779,55 @@ public: inline punctuationToken pToken() const; //- Assign to a punctuation token - inline void pToken(const punctuationToken p); + inline void pToken(punctuationToken p); - //- Return label value. - // Report FatalIOError and return \b 0 if token is not LABEL + //- Return int32 value, convert from other integer type or Error + inline int32_t int32Token() const; + + //- Assign a int32 value token + inline void int32Token(int32_t val); + + //- Return int64 value, convert from other integer type or Error + inline int64_t int64Token() const; + + //- Assign a int64 value token + inline void int64Token(int64_t val); + + //- Return int32 value, convert from other integer type or Error + inline uint32_t uint32Token() const; + + //- Assign a uint32 value token + inline void uint32Token(uint32_t val); + + //- Return int64 value, convert from other integer type or Error + inline uint64_t uint64Token() const; + + //- Assign a uint64 value token + inline void uint64Token(uint64_t val); + + //- Return integer type as label value or Error inline label labelToken() const; - //- Assign to a label token + //- Return integer type as uLabel value or Error + inline uLabel uLabelToken() const; + + //- Assign to a label (int32 or int64) token inline void labelToken(const label val); //- Return float value. // Report FatalIOError and return \b 0 if token is not FLOAT inline float floatToken() const; + //- Assign to a float token + inline void floatToken(const float val); + //- Return double value. // Report FatalIOError and return \b 0 if token is not DOUBLE inline double doubleToken() const; + //- Assign to a double token + inline void doubleToken(const double val); + //- Return float or double value. // Report FatalIOError and return \b 0 if token is not a // FLOAT or DOUBLE @@ -753,7 +835,7 @@ public: //- Return label, float or double value. // Report FatalIOError and return \b 0 if token is not a - // LABEL, FLOAT or DOUBLE + // an integer type, FLOAT or DOUBLE inline scalar number() const; //- Return const reference to the word contents. @@ -841,14 +923,23 @@ public: //- Copy assign from punctuation inline void operator=(const punctuationToken p); - //- Copy assign from label - inline void operator=(const label val); + //- Copy assign from int32_t + inline void operator=(int32_t val); + + //- Copy assign from int64_t + inline void operator=(int64_t val); + + //- Copy assign from uint32_t + inline void operator=(uint32_t val); + + //- Copy assign from uint64_t + inline void operator=(uint64_t val); //- Copy assign from float - inline void operator=(const float val); + inline void operator=(float val); //- Copy assign from double - inline void operator=(const double val); + inline void operator=(double val); //- Copy assign from word content inline void operator=(const word& w); @@ -873,20 +964,29 @@ public: inline bool operator==(const token& tok) const; inline bool operator==(const punctuationToken p) const noexcept; - inline bool operator==(const label val) const noexcept; + inline bool operator==(const int32_t val) const noexcept; + inline bool operator==(const int64_t val) const noexcept; + inline bool operator==(const uint32_t val) const noexcept; + inline bool operator==(const uint64_t val) const noexcept; inline bool operator==(const float val) const noexcept; inline bool operator==(const double val) const noexcept; - inline bool operator==(const std::string& s) const; + inline bool operator==(const std::string&) const; // Inequality - inline bool operator!=(const token& tok) const; - inline bool operator!=(const punctuationToken p) const noexcept; - inline bool operator!=(const label val) const noexcept; - inline bool operator!=(const float val) const noexcept; - inline bool operator!=(const double val) const noexcept; - inline bool operator!=(const std::string& s) const; + bool operator!=(const token& t) const { return !operator==(t); } + bool operator!=(punctuationToken p) const noexcept + { + return !operator==(p); + } + bool operator!=(int32_t b) const noexcept { return !operator==(b); } + bool operator!=(int64_t b) const noexcept { return !operator==(b); } + bool operator!=(uint32_t b) const noexcept { return !operator==(b); } + bool operator!=(uint64_t b) const noexcept { return !operator==(b); } + bool operator!=(float b) const noexcept { return !operator==(b); } + bool operator!=(double b) const noexcept { return !operator==(b); } + bool operator!=(const std::string& s) const { return !operator==(s); } // IOstream Operators @@ -907,11 +1007,11 @@ public: //- Token is FLOAT // \deprecated(2020-01) - isFloat() - bool isFloatScalar() const { return isFloat(); }; + bool isFloatScalar() const noexcept { return isFloat(); }; //- Token is DOUBLE // \deprecated(2020-01) - isDouble() - bool isDoubleScalar() const { return isDouble(); } + bool isDoubleScalar() const noexcept { return isDouble(); } //- Return float value. // \deprecated(2020-01) - floatToken() diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index f3996589f8..370db69c4c 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011-2016,2024 OpenFOAM Foundation Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -34,7 +34,7 @@ inline Foam::token Foam::token::boolean(bool on) noexcept { token tok; tok.type_ = tokenType::BOOL; - tok.data_.labelVal = on; + tok.data_.flagVal = on; return tok; } @@ -50,6 +50,18 @@ inline Foam::token Foam::token::flag(int bitmask) noexcept } +inline bool Foam::token::is_integerToken(tokenType tokType) noexcept +{ + return + ( + tokType == tokenType::INTEGER_32 + || tokType == tokenType::INTEGER_64 + || tokType == tokenType::UNSIGNED_INTEGER_32 + || tokType == tokenType::UNSIGNED_INTEGER_64 + ); +} + + inline bool Foam::token::is_wordToken(tokenType tokType) noexcept { return @@ -115,6 +127,41 @@ inline void Foam::token::setUndefined() noexcept } +// inline bool Foam::token:is_pointer() const noexcept +// { +// return (isWord() || isString() || isCompound()); +// } + +template +inline Type Foam::token::getIntegral(const char* expected) const +{ + switch (type_) + { + case tokenType::INTEGER_32 : return data_.int32Val; + case tokenType::INTEGER_64 : return data_.int64Val; + case tokenType::UNSIGNED_INTEGER_32 : return data_.uint32Val; + case tokenType::UNSIGNED_INTEGER_64 : return data_.uint64Val; + default: parseError(expected); return 0; + } +} + + +template +inline Type Foam::token::getArithmetic(const char* expected) const +{ + switch (type_) + { + case tokenType::INTEGER_32 : return data_.int32Val; + case tokenType::INTEGER_64 : return data_.int64Val; + case tokenType::UNSIGNED_INTEGER_32 : return data_.uint32Val; + case tokenType::UNSIGNED_INTEGER_64 : return data_.uint64Val; + case tokenType::FLOAT : return data_.floatVal; + case tokenType::DOUBLE : return data_.doubleVal; + default: parseError(expected); return 0; + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline constexpr Foam::token::token() noexcept @@ -190,17 +237,47 @@ inline Foam::token::token(punctuationToken p, label lineNum) noexcept } -inline Foam::token::token(const label val, label lineNum) noexcept +inline Foam::token::token(int32_t val, label lineNum) noexcept : data_(), - type_(tokenType::LABEL), + type_(tokenType::INTEGER_32), line_(lineNum) { - data_.labelVal = val; + data_.int32Val = val; } -inline Foam::token::token(const float val, label lineNum) noexcept +inline Foam::token::token(int64_t val, label lineNum) noexcept +: + data_(), + type_(tokenType::INTEGER_64), + line_(lineNum) +{ + data_.int64Val = val; +} + + +inline Foam::token::token(uint32_t val, label lineNum) noexcept +: + data_(), + type_(tokenType::UNSIGNED_INTEGER_32), + line_(lineNum) +{ + data_.uint32Val = val; +} + + +inline Foam::token::token(uint64_t val, label lineNum) noexcept +: + data_(), + type_(tokenType::UNSIGNED_INTEGER_64), + line_(lineNum) +{ + data_.uint64Val = val; +} + + +inline Foam::token::token(float val, label lineNum) noexcept : data_(), type_(tokenType::FLOAT), @@ -210,7 +287,7 @@ inline Foam::token::token(const float val, label lineNum) noexcept } -inline Foam::token::token(const double val, label lineNum) noexcept +inline Foam::token::token(double val, label lineNum) noexcept : data_(), type_(tokenType::DOUBLE), @@ -425,13 +502,13 @@ inline bool Foam::token::setType(token::tokenType tokType) noexcept switch (tokType) { + case tokenType::FLAG: case tokenType::BOOL: - case tokenType::LABEL: { switch (type_) { + case tokenType::FLAG: case tokenType::BOOL: - case tokenType::LABEL: type_ = tokType; return true; break; @@ -537,9 +614,13 @@ inline bool Foam::token::isBool() const noexcept inline bool Foam::token::boolToken() const { - if (type_ == tokenType::BOOL || type_ == tokenType::LABEL) + if (type_ == tokenType::BOOL) { - return data_.labelVal; + return data_.flagVal; + } + else if (type_ == tokenType::INTEGER_32) + { + return data_.int32Val; } parseError("bool"); @@ -551,7 +632,7 @@ inline void Foam::token::boolToken(bool on) { reset(); type_ = tokenType::BOOL; - data_.labelVal = on; + data_.flagVal = on; } @@ -579,7 +660,7 @@ inline bool Foam::token::isPunctuation() const noexcept } -inline bool Foam::token::isPunctuation(const punctuationToken p) const noexcept +inline bool Foam::token::isPunctuation(punctuationToken p) const noexcept { return ( @@ -606,12 +687,12 @@ inline Foam::token::punctuationToken Foam::token::pToken() const return data_.punctuationVal; } - parseError("punctuation character"); + parseError("punctuation"); return punctuationToken::NULL_TOKEN; } -inline void Foam::token::pToken(const punctuationToken p) +inline void Foam::token::pToken(punctuationToken p) { reset(); type_ = tokenType::PUNCTUATION; @@ -619,57 +700,224 @@ inline void Foam::token::pToken(const punctuationToken p) } -inline bool Foam::token::isLabel() const noexcept +inline bool Foam::token::isIntType() const noexcept { - return + return is_integerToken(type_); +} + + +// inline bool Foam::token::isSignedIntType() const noexcept +// { +// return +// ( +// (type_ == tokenType::INTEGER_32) +// || (type_ == tokenType::INTEGER_64) +// ); +// } +// +// +// inline bool Foam::token::isUnsignedIntType() const noexcept +// { +// return +// ( +// (type_ == tokenType::UNSIGNED_INTEGER_32) +// || (type_ == tokenType::UNSIGNED_INTEGER_64) +// ); +// } + + +inline bool Foam::token::is_int32() const noexcept +{ + return (type_ == tokenType::INTEGER_32) || ( - type_ == tokenType::LABEL - // FUTURE? - // || type_ == tokenType::INT32 - // || type_ == tokenType::INT64 + (type_ == tokenType::INTEGER_64) + ? (data_.int64Val >= INT32_MIN && data_.int64Val <= INT32_MAX) + : (type_ == tokenType::UNSIGNED_INTEGER_32) + ? (data_.uint32Val <= INT32_MAX) + : + ( + type_ == tokenType::UNSIGNED_INTEGER_64 + && data_.uint64Val <= INT32_MAX + ) ); } -inline bool Foam::token::isLabel(const label value) const noexcept +inline int32_t Foam::token::int32Token() const { - // FUTURE? - // return - // ( - // type_ == tokenType::LABEL - // ? value == data_.labelVal - // : type_ == tokenType::INT32 - // ? value == data_.int32Val - // : type_ == tokenType::INT64 - // ? value == data_.int64Val - // : false - // ); + return getIntegral("int32"); +} + +inline void Foam::token::int32Token(int32_t val) +{ + reset(); + type_ = tokenType::INTEGER_32; + data_.int32Val = val; +} + + +inline bool Foam::token::is_int64() const noexcept +{ + return (type_ == tokenType::INTEGER_64) || + ( + (type_ == tokenType::INTEGER_32) + || (type_ == tokenType::UNSIGNED_INTEGER_32) + || ( + type_ == tokenType::UNSIGNED_INTEGER_64 + && data_.uint64Val <= INT64_MAX + ) + ); +} + + +inline int64_t Foam::token::int64Token() const +{ + return getIntegral("int64"); +} + + +inline void Foam::token::int64Token(int64_t val) +{ + reset(); + type_ = tokenType::INTEGER_64; + data_.int64Val = val; +} + + +inline bool Foam::token::is_uint32() const noexcept +{ + return (type_ == tokenType::UNSIGNED_INTEGER_32) || + ( + (type_ == tokenType::INTEGER_32) + ? (data_.int32Val >= 0) + : (type_ == tokenType::INTEGER_64) + ? (data_.int64Val >= 0 && data_.int64Val <= UINT32_MAX) + : + ( + type_ == tokenType::UNSIGNED_INTEGER_64 + && data_.uint64Val <= UINT32_MAX + ) + ); +} + + +inline uint32_t Foam::token::uint32Token() const +{ + return getIntegral("uint32"); +} + + +inline void Foam::token::uint32Token(uint32_t val) +{ + reset(); + type_ = tokenType::UNSIGNED_INTEGER_32; + data_.uint32Val = val; +} + + +inline bool Foam::token::is_uint64() const noexcept +{ return ( - type_ == tokenType::LABEL - && value == data_.labelVal + ( + type_ == tokenType::UNSIGNED_INTEGER_32 + || type_ == tokenType::UNSIGNED_INTEGER_64 + ) + || + ( + (type_ == tokenType::INTEGER_32) ? (data_.int32Val >= 0) + : (type_ == tokenType::INTEGER_64 && data_.int64Val >= 0) + ) ); } +inline uint64_t Foam::token::uint64Token() const +{ + return getIntegral("uint64"); +} + + +inline void Foam::token::uint64Token(uint64_t val) +{ + reset(); + type_ = tokenType::UNSIGNED_INTEGER_64; + data_.uint64Val = val; +} + + +inline bool Foam::token::isLabel() const noexcept +{ + if constexpr (sizeof(Foam::label) == sizeof(int32_t)) + { + return is_int32(); + } + else + { + return is_int64(); + } +} + + +inline bool Foam::token::isULabel() const noexcept +{ + if constexpr (sizeof(Foam::label) == sizeof(int32_t)) + { + return is_uint32(); + } + else + { + return is_uint64(); + } +} + + inline Foam::label Foam::token::labelToken() const { - if (type_ == tokenType::LABEL) - { - return data_.labelVal; - } + return getIntegral