diff --git a/applications/test/OListStream/Test-OListStream.C b/applications/test/OListStream/Test-OListStream.C index e24a9e55ee81e4f74fe48414126b4b7c74b5b2d7..c0e19de3cde2c979814203b23ce9dae11e567828 100644 --- a/applications/test/OListStream/Test-OListStream.C +++ b/applications/test/OListStream/Test-OListStream.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -214,7 +214,7 @@ int main(int argc, char *argv[]) { OListStream os2; - os2.indentSize() = 0; + os2.indentSize(0); outputDict(os2); diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.C index c63ddc5fe412cb50d952083c843f066759135ab0..96dfbe8fb737fd26ce04d3f2ea4e475c24407406 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2015 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -134,7 +134,7 @@ Foam::cv2DControls::cv2DControls void Foam::cv2DControls::write(Ostream& os) const { - os.indentLevel() = 1; + const auto oldLevel = os.indentLevel(1); os.precision(2); os.flags(ios_base::scientific); @@ -148,6 +148,8 @@ void Foam::cv2DControls::write(Ostream& os) const << indent << "ppDist_ : " << ppDist_ << nl << indent << "minEdgeLen2_ : " << minEdgeLen2_ << nl << token::END_BLOCK << endl; + + os.indentLevel(oldLevel); } diff --git a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C index 32a81d379428e83bf959e89c62554f9e63070737..af91270a9e59fc055c131ac49e495020a8fd59ae 100644 --- a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C +++ b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -96,7 +97,7 @@ int main(int argc, char *argv[]) break; } - if (!fieldName.isWord() || fieldName.wordToken() != "CELL") + if (!fieldName.isWord("CELL")) { FatalErrorInFunction << "Expected first CELL, found " diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C b/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C index 19cac26bff9b65e84d3fd2beabc32c9fb07fc180..45bb1c1fea79de798eb1da4e81711133198b1213 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C @@ -139,59 +139,39 @@ Foam::Istream& Foam::PackedList<Width>::read(Istream& is) } } } - else if (firstTok.isPunctuation()) + else if (firstTok.isPunctuation(token::BEGIN_LIST)) { - if (firstTok.pToken() == token::BEGIN_LIST) - { - token nextTok(is); - is.fatalCheck(FUNCTION_NAME); - - while - ( - !( nextTok.isPunctuation() - && nextTok.pToken() == token::END_LIST - ) - ) - { - is.putBack(nextTok); - list.append(list.readValue(is)); + token nextTok(is); + is.fatalCheck(FUNCTION_NAME); - is >> nextTok; - is.fatalCheck(FUNCTION_NAME); - } - } - else if (firstTok.pToken() == token::BEGIN_BLOCK) + while (!nextTok.isPunctuation(token::END_LIST)) { - token nextTok(is); - is.fatalCheck(FUNCTION_NAME); + is.putBack(nextTok); + list.append(list.readValue(is)); - while - ( - !( nextTok.isPunctuation() - && nextTok.pToken() == token::END_BLOCK - ) - ) - { - is.putBack(nextTok); - list.setPair(is); - - is >> nextTok; - is.fatalCheck(FUNCTION_NAME); - } + is >> nextTok; + is.fatalCheck(FUNCTION_NAME); } - else + } + else if (firstTok.isPunctuation(token::BEGIN_BLOCK)) + { + token nextTok(is); + is.fatalCheck(FUNCTION_NAME); + + while (!nextTok.isPunctuation(token::END_BLOCK)) { - FatalIOErrorInFunction(is) - << "incorrect first token, expected '(', found " - << firstTok.info() - << exit(FatalIOError); + is.putBack(nextTok); + list.setPair(is); + + is >> nextTok; + is.fatalCheck(FUNCTION_NAME); } } else { FatalIOErrorInFunction(is) << "incorrect first token, expected <int>, '(' or '{', found " - << firstTok.info() + << firstTok.info() << nl << exit(FatalIOError); } diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C index 7adb7c00614d3756c7c8bbdeb2a37c64805d6bfd..c1692542a97ebd07d037e2e60d2f8942df2ccf88 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -92,23 +92,10 @@ void Foam::HashPtrTable<T, Key, Hash>::readIstream // Read end of contents is.readEndList("HashPtrTable"); } - else if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " << firstToken.info() - << exit(FatalIOError); - } - token lastToken(is); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { is.putBack(lastToken); Key key; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C index ae0ca036e46eee418b54e9c4676fd38c5699d202..888201f1c37601986af8f5f09347de0d363d595f 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -203,23 +203,10 @@ Foam::Istream& Foam::operator>> // Read end of contents is.readEndList("HashTable"); } - else if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " << firstToken.info() - << exit(FatalIOError); - } - token lastToken(is); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { is.putBack(lastToken); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C index c10293b901c80686c5ffc34ea873ea3dd89349b4..48fcff12d0785a55b417f07d4b4f6c2a0f678089 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,25 +90,12 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew) // Read end of contents is.readEndList("ILList"); } - else if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " << firstToken.info() - << exit(FatalIOError); - } - token lastToken(is); is.fatalCheck(FUNCTION_NAME); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { is.putBack(lastToken); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index 1994232d76269b8e21316a6e132f3ea4d9773938..9941055c426d8f945d8a19f59179835ed19e1619 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -86,25 +86,12 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& lst) // Read end of contents is.readEndList("LList"); } - else if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " << firstToken.info() - << exit(FatalIOError); - } - token lastToken(is); is.fatalCheck(FUNCTION_NAME); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { is.putBack(lastToken); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C index a7fe35090b0d06ff2eb2b4db3293d5562fbcb414..78f0038f34ba3eb173d2df81e67a39f13d230701 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -91,25 +91,12 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew) // Read end of contents is.readEndList("LPtrList"); } - else if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " << firstToken.info() - << exit(FatalIOError); - } - token lastToken(is); is.fatalCheck(FUNCTION_NAME); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { is.putBack(lastToken); this->append(inew(is).ptr()); diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index 534a18175963b81408acf655fb5ab7e7257ce6da..8458c9cc2f3bc3322893655424f92a378dda8464 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,9 +55,10 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& list) is.fatalCheck(FUNCTION_NAME); - // Compound: simply transfer contents if (firstToken.isCompound()) { + // Compound: simply transfer contents + list.transfer ( dynamicCast<token::Compound<List<T>>> @@ -65,14 +66,11 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& list) firstToken.transferCompoundToken(is) ) ); - - return is; } - - - // Label: could be int(..), int{...} or just a plain '0' - if (firstToken.isLabel()) + else if (firstToken.isLabel()) { + // Label: could be int(..), int{...} or just a plain '0' + const label len = firstToken.labelToken(); // Resize to length read @@ -140,37 +138,24 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& list) "reading the binary block" ); } - - return is; } - - - // "(...)" : read as SLList and transfer contents - if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, expected '(', found " - << firstToken.info() - << exit(FatalIOError); - } + // "(...)" : read as SLList and transfer contents is.putBack(firstToken); // Putback the opening bracket - SLList<T> sll(is); // Read as singly-linked list // Reallocate and move assign list elements list = std::move(sll); - - return is; } - - - FatalIOErrorInFunction(is) - << "incorrect first token, expected <int> or '(', found " - << firstToken.info() - << exit(FatalIOError); + else + { + FatalIOErrorInFunction(is) + << "incorrect first token, expected <int> or '(', found " + << firstToken.info() << nl + << exit(FatalIOError); + } return is; } diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index b5369cdb9fe80d7402f730a932b5a85c42998578..c77d98c0cfa256d176318e9a2d75a29ef306084f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -170,9 +170,10 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list) is.fatalCheck("operator>>(Istream&, UList<T>&) : reading first token"); - // Compound: simply transfer contents if (firstToken.isCompound()) { + // Compound: simply transfer contents + List<T> elems; elems.transfer ( @@ -197,14 +198,11 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list) { list[i] = std::move(elems[i]); } - - return is; } - - - // Label: could be int(..), int{...} or just a plain '0' - if (firstToken.isLabel()) + else if (firstToken.isLabel()) { + // Label: could be int(..), int{...} or just a plain '0' + const label inputLen = firstToken.labelToken(); // List lengths must match @@ -276,24 +274,12 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list) "operator>>(Istream&, UList<T>&) : reading the binary block" ); } - - return is; } - - - // "(...)" : read as SLList and transfer contents - if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, expected '(', found " - << firstToken.info() - << exit(FatalIOError); - } + // "(...)" : read as SLList and transfer contents is.putBack(firstToken); // Putback the opening bracket - SLList<T> sll(is); // Read as singly-linked list // List lengths must match @@ -310,15 +296,14 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list) { list[i] = std::move(sll.removeHead()); } - - return is; } - - - FatalIOErrorInFunction(is) - << "incorrect first token, expected <int> or '(', found " - << firstToken.info() - << exit(FatalIOError); + else + { + FatalIOErrorInFunction(is) + << "incorrect first token, expected <int> or '(', found " + << firstToken.info() << nl + << exit(FatalIOError); + } return is; } diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListIO.C b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListIO.C index 67017d0c16502017fb596f1312a070d1795c55b7..d89b403bd02be80d0c956e3045b322e3038c9c45 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListIO.C +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,10 +49,10 @@ void Foam::PtrList<T>::readIstream(Istream& is, const INew& inew) "reading first token" ); - - // Label: could be int(..), int{...} or just a plain '0' if (firstToken.isLabel()) { + // Label: could be int(..), int{...} or just a plain '0' + // Read size of list const label len = firstToken.labelToken(); @@ -98,33 +98,17 @@ void Foam::PtrList<T>::readIstream(Istream& is, const INew& inew) // Read end of contents is.readEndList("PtrList"); - - return; } - - - // "(...)" : read as SLList and transfer contents - // This would be more efficient (fewer allocations, lower overhead) - // using a DynamicList, but then we have circular dependencies - if (firstToken.isPunctuation()) + else if (firstToken.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " << firstToken.info() - << exit(FatalIOError); - } + // "(...)" : read as SLList and transfer contents + // This would be more efficient (fewer allocations, lower overhead) + // using a DynamicList, but then we have circular dependencies SLList<T*> slList; token lastToken(is); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { is.putBack(lastToken); @@ -147,14 +131,14 @@ void Foam::PtrList<T>::readIstream(Istream& is, const INew& inew) { set(i++, ptr); } - - return; } - - FatalIOErrorInFunction(is) - << "incorrect first token, expected <int> or '(', found " - << firstToken.info() - << exit(FatalIOError); + else + { + FatalIOErrorInFunction(is) + << "incorrect first token, expected <int> or '(', found " + << firstToken.info() << nl + << exit(FatalIOError); + } } diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index fe6aed04bbd07e6f5f5f0cff20d18e853690422e..7726a6d76a605dde2cbeb1c536ed56e4ff578920 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,12 +62,7 @@ bool Foam::IOobject::readHeader(Istream& is) token firstToken(is); - if - ( - is.good() - && firstToken.isWord() - && firstToken.wordToken() == "FoamFile" - ) + if (is.good() && firstToken.isWord("FoamFile")) { const dictionary headerDict(is); diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index d95db4561cb07e82d66cda70471f710b0ffb363f..41234f750975f9771d3ed1131217d2369d0ef01e 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -1084,12 +1084,7 @@ Foam::label Foam::decomposedBlockData::numBlocks(const fileName& fName) // FoamFile header token firstToken(is); - if - ( - is.good() - && firstToken.isWord() - && firstToken.wordToken() == "FoamFile" - ) + if (is.good() && firstToken.isWord("FoamFile")) { dictionary headerDict(is); is.version(headerDict.get<token>("version")); diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index d6f4eab9c5cc2ada376491291c1c637b228383d0..e27dcc0c6adcaca510f4a92a153d317223ea2fc6 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -171,32 +171,36 @@ public: //- Add indentation characters virtual void indent() = 0; - //- Return indent level - unsigned short indentSize() const + //- Return indent size (spaces per level) + unsigned short indentSize() const noexcept { return indentSize_; } - //- Access to indent size - unsigned short& indentSize() + //- Change indent size (spaces per level), return old value + unsigned short indentSize(unsigned short val) noexcept { - return indentSize_; + auto old(indentSize_); + indentSize_ = val; + return old; } - //- Return indent level - unsigned short indentLevel() const + //- Return the indent level + unsigned short indentLevel() const noexcept { return indentLevel_; } - //- Access to indent level - unsigned short& indentLevel() + //- Change the indent level, return old value + unsigned short indentLevel(unsigned short val) noexcept { - return indentLevel_; + auto old(indentLevel_); + indentLevel_ = val; + return old; } //- Increment the indent level - void incrIndent() + void incrIndent() noexcept { ++indentLevel_; } @@ -293,6 +297,21 @@ public: { return const_cast<Ostream&>(*this); } + + + // Housekeeping + + //- Access to indent level + unsigned short& indentLevel() noexcept + { + return indentLevel_; + } + + //- Access to indent size + unsigned short& indentSize() noexcept + { + return indentSize_; + } }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C index 7bd2b3764d8d3930b224b7d12546c84cee51a2e4..eed1e261cbc507d025753ae558f7a4e5de86c2a7 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -202,7 +202,7 @@ Foam::Istream& Foam::UIPstream::read(token& t) // Set the line number of this token to the current stream line number - t.lineNumber() = lineNumber(); + t.lineNumber(this->lineNumber()); // Analyse input starting with this character. switch (c) diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index cfc56d7e9ad2db39af05cef6ce79b861d25b01c8..d1c4adc93d152563438574d3527417f9f4503321 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-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -175,7 +175,7 @@ Foam::Istream& Foam::ISstream::read(token& t) char c = nextValid(); // Set the line number of this token to the current stream line number - t.lineNumber() = lineNumber(); + t.lineNumber(this->lineNumber()); // Return on error if (!c) diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 8fca84428d867fb736aa2add85ea851dc66c7bb9..4736a1eb46340dcc0b1b87ba7fd9220f6eac65ed 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -285,11 +285,11 @@ Foam::Istream& Foam::ITstream::read(token& tok) if (size()) { - tok.lineNumber() = tokenList::last().lineNumber(); + tok.lineNumber(tokenList::last().lineNumber()); } else { - tok.lineNumber() = lineNumber(); + tok.lineNumber(this->lineNumber()); } } diff --git a/src/OpenFOAM/db/IOstreams/token/token.C b/src/OpenFOAM/db/IOstreams/token/token.C index 6eac51cc1f7e2cda71cbc1564aa53d1ffb9e877d..313ca75fd186db73ace6a6e489a7157a831ea22c 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.C +++ b/src/OpenFOAM/db/IOstreams/token/token.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -94,7 +94,7 @@ Foam::token::compound& Foam::token::transferCompoundToken() parseError("compound"); } - if (data_.compoundPtr->empty()) + if (data_.compoundPtr->moved()) { FatalErrorInFunction << "compound has already been transferred from token\n " @@ -102,7 +102,7 @@ Foam::token::compound& Foam::token::transferCompoundToken() } else { - data_.compoundPtr->empty() = true; + data_.compoundPtr->moved(true); } return *data_.compoundPtr; @@ -116,7 +116,7 @@ Foam::token::compound& Foam::token::transferCompoundToken(const Istream& is) parseError("compound"); } - if (data_.compoundPtr->empty()) + if (data_.compoundPtr->moved()) { FatalIOErrorInFunction(is) << "compound has already been transferred from token\n " @@ -124,7 +124,7 @@ Foam::token::compound& Foam::token::transferCompoundToken(const Istream& is) } else { - data_.compoundPtr->empty() = true; + data_.compoundPtr->moved(true); } return *data_.compoundPtr; diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 407a1c74c2db6c534326343bb805e9f7ad660110..4f26bc3ef01d05e9b775a05477830f0ef69cb886 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -115,22 +115,17 @@ public: enum punctuationToken : char { NULL_TOKEN = '\0', //!< Nul character - SPACE = ' ', //!< Space [isspace] TAB = '\t', //!< Tab [isspace] NL = '\n', //!< Newline [isspace] + SPACE = ' ', //!< Space [isspace] - END_STATEMENT = ';', //!< End entry [#isseparator] - BEGIN_LIST = '(', //!< Begin list [#isseparator] - END_LIST = ')', //!< End list [#isseparator] - BEGIN_SQR = '[', //!< Begin dimensions [#isseparator] - END_SQR = ']', //!< End dimensions [#isseparator] - BEGIN_BLOCK = '{', //!< Begin block [#isseparator] - END_BLOCK = '}', //!< End block [#isseparator] COLON = ':', //!< Colon [#isseparator] + SEMICOLON = ';', //!< Semicolon [#isseparator] COMMA = ',', //!< Comma [#isseparator] HASH = '#', //!< Hash - directive or verbatim string DOLLAR = '$', //!< Dollar - start variable - ATSYM = '@', //!< At + QUESTION = '?', //!< Question mark (eg, ternary) + ATSYM = '@', //!< The 'at' symbol SQUOTE = '\'', //!< Single quote DQUOTE = '"', //!< Double quote @@ -140,8 +135,25 @@ public: MULTIPLY = '*', //!< Multiply [#isseparator] DIVIDE = '/', //!< Divide [#isseparator] - BEGIN_STRING = DQUOTE, //!< Begin string with double quote - END_STRING = DQUOTE //!< End string with double quote + LPAREN = '(', //!< Left parenthesis [#isseparator] + RPAREN = ')', //!< Right parenthesis [#isseparator] + LSQUARE = '[', //!< Left square bracket [#isseparator] + RSQUARE = ']', //!< Right square bracket [#isseparator] + LBRACE = '{', //!< Left brace [#isseparator] + RBRACE = '}', //!< Right brace [#isseparator] + + // With semantically meaning + + END_STATEMENT = SEMICOLON, //!< End entry [#isseparator] + BEGIN_LIST = LPAREN, //!< Begin list [#isseparator] + END_LIST = RPAREN, //!< End list [#isseparator] + BEGIN_SQR = LSQUARE, //!< Begin dimensions [#isseparator] + END_SQR = RSQUARE, //!< End dimensions [#isseparator] + BEGIN_BLOCK = LBRACE, //!< Begin block [#isseparator] + END_BLOCK = RBRACE, //!< End block [#isseparator] + + BEGIN_STRING = DQUOTE, //!< Begin string with double quote + END_STRING = DQUOTE //!< End string with double quote }; @@ -150,7 +162,8 @@ public: : public refCount { - bool empty_; + //- Has compound token already been transferred + bool moved_; //- No copy construct compound(const compound&) = delete; @@ -179,7 +192,7 @@ public: //- Default construct constexpr compound() noexcept : - empty_(false) + moved_(false) {} //- Construct compound from Istream @@ -195,16 +208,16 @@ public: //- Test if name is a known (registered) compound type static bool isCompound(const word& name); - //- Has compound been transferred? - bool empty() const noexcept + //- Get compound transferred status + bool moved() const noexcept { - return empty_; + return moved_; } - //- Access to empty - bool& empty() noexcept + //- Set compound transferred status + void moved(bool b) noexcept { - return empty_; + moved_ = b; } //- The size of the underlying content @@ -256,9 +269,6 @@ public: // Member Functions - //- Using empty from compound refCount - using token::compound::empty; - //- The size of the underlying content virtual label size() const { @@ -416,8 +426,8 @@ public: //- The line number for the token inline label lineNumber() const noexcept; - //- The line number for the token - inline label& lineNumber() noexcept; + //- Change token line number, return old value + inline label lineNumber(const label lineNum) noexcept; //- True if token is not UNDEFINED or ERROR inline bool good() const noexcept; @@ -437,6 +447,9 @@ public: //- Token is PUNCTUATION inline bool isPunctuation() const noexcept; + //- True if token is PUNCTUATION and equal to parameter + inline bool isPunctuation(const punctuationToken p) const noexcept; + //- Token is PUNCTUATION and isseparator inline bool isSeparator() const noexcept; @@ -458,6 +471,9 @@ public: //- Token is WORD or DIRECTIVE word inline bool isWord() const noexcept; + //- Token is WORD or DIRECTIVE word and equal to parameter + inline bool isWord(const std::string& s) const; + //- Token is DIRECTIVE (word variant) inline bool isDirective() const noexcept; @@ -599,20 +615,20 @@ public: // Equality inline bool operator==(const token& tok) const; - inline bool operator==(const punctuationToken p) const; - inline bool operator==(const label val) const; - inline bool operator==(const floatScalar val) const; - inline bool operator==(const doubleScalar val) const; + inline bool operator==(const punctuationToken p) const noexcept; + inline bool operator==(const label val) const noexcept; + inline bool operator==(const floatScalar val) const noexcept; + inline bool operator==(const doubleScalar val) const noexcept; inline bool operator==(const std::string& s) const; // Inequality inline bool operator!=(const token& tok) const; - inline bool operator!=(const punctuationToken p) const; - inline bool operator!=(const label val) const; - inline bool operator!=(const floatScalar val) const; - inline bool operator!=(const doubleScalar val) const; + inline bool operator!=(const punctuationToken p) const noexcept; + inline bool operator!=(const label val) const noexcept; + inline bool operator!=(const floatScalar val) const noexcept; + inline bool operator!=(const doubleScalar val) const noexcept; inline bool operator!=(const std::string& s) const; @@ -628,6 +644,10 @@ public: // Housekeeping + //- Write access for the token line number + // \deprecated(2021-03) - use lineNumber(label) + label& lineNumber() noexcept { return line_; } + //- Token is FLOAT // \deprecated(2020-01) - isFloat() bool isFloatScalar() const { return isFloat(); }; @@ -670,12 +690,23 @@ Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip); // Handling of compound types -#define defineCompoundTypeName(Type, Name) \ +//- Define compound using \a Type for its name +#define defineCompoundTypeName(Type, UnusedTag) \ defineTemplateTypeNameAndDebugWithName(token::Compound<Type>, #Type, 0); -#define addCompoundToRunTimeSelectionTable(Type, Name) \ +//- Define compound using \a Name for its name +#define defineNamedCompoundTypeName(Type, Name) \ + defineTemplateTypeNameAndDebugWithName(token::Compound<Type>, #Name, 0); + +//- Add compound to selection table, lookup using typeName +#define addCompoundToRunTimeSelectionTable(Type, Tag) \ + token::compound::addIstreamConstructorToTable<token::Compound<Type>> \ + add##Tag##IstreamConstructorToTable_; + +//- Add compound to selection table, lookup as \a Name +#define addNamedCompoundToRunTimeSelectionTable(Type, Tag, Name) \ token::compound::addIstreamConstructorToTable<token::Compound<Type>> \ - add##Name##IstreamConstructorToTable_; + add##Tag##IstreamConstructorToTable_(#Name); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index eda92d596808c341589c25f474c2e8e67b3a3649..fdd5916274ddc78959e22ecfec9a758bcda270a7 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -390,9 +390,11 @@ inline Foam::label Foam::token::lineNumber() const noexcept } -inline Foam::label& Foam::token::lineNumber() noexcept +inline Foam::label Foam::token::lineNumber(const label lineNum) noexcept { - return line_; + label old(line_); + line_ = lineNum; + return old; } @@ -456,15 +458,13 @@ inline bool Foam::token::isPunctuation() const noexcept } -inline Foam::token::punctuationToken Foam::token::pToken() const +inline bool Foam::token::isPunctuation(const punctuationToken p) const noexcept { - if (type_ == tokenType::PUNCTUATION) - { - return data_.punctuationVal; - } - - parseError("punctuation character"); - return punctuationToken::NULL_TOKEN; + return + ( + type_ == tokenType::PUNCTUATION + && data_.punctuationVal == p + ); } @@ -478,6 +478,18 @@ inline bool Foam::token::isSeparator() const noexcept } +inline Foam::token::punctuationToken Foam::token::pToken() const +{ + if (type_ == tokenType::PUNCTUATION) + { + return data_.punctuationVal; + } + + parseError("punctuation character"); + return punctuationToken::NULL_TOKEN; +} + + inline bool Foam::token::isLabel() const noexcept { return (type_ == tokenType::LABEL); @@ -590,6 +602,12 @@ inline bool Foam::token::isWord() const noexcept } +inline bool Foam::token::isWord(const std::string& s) const +{ + return (isWord() && s == *data_.wordPtr); +} + + inline bool Foam::token::isDirective() const noexcept { return (type_ == tokenType::DIRECTIVE); @@ -884,9 +902,9 @@ inline bool Foam::token::operator==(const token& tok) const } -inline bool Foam::token::operator==(const punctuationToken p) const +inline bool Foam::token::operator==(const punctuationToken p) const noexcept { - return (type_ == tokenType::PUNCTUATION && data_.punctuationVal == p); + return isPunctuation(p); } @@ -901,7 +919,7 @@ inline bool Foam::token::operator==(const std::string& s) const } -inline bool Foam::token::operator==(const label val) const +inline bool Foam::token::operator==(const label val) const noexcept { return ( @@ -911,7 +929,7 @@ inline bool Foam::token::operator==(const label val) const } -inline bool Foam::token::operator==(const floatScalar val) const +inline bool Foam::token::operator==(const floatScalar val) const noexcept { return ( @@ -921,7 +939,7 @@ inline bool Foam::token::operator==(const floatScalar val) const } -inline bool Foam::token::operator==(const doubleScalar val) const +inline bool Foam::token::operator==(const doubleScalar val) const noexcept { return ( @@ -937,25 +955,25 @@ inline bool Foam::token::operator!=(const token& tok) const } -inline bool Foam::token::operator!=(const punctuationToken p) const +inline bool Foam::token::operator!=(const punctuationToken p) const noexcept { - return !operator==(p); + return !isPunctuation(p); } -inline bool Foam::token::operator!=(const label val) const +inline bool Foam::token::operator!=(const label val) const noexcept { return !operator==(val); } -inline bool Foam::token::operator!=(const floatScalar val) const +inline bool Foam::token::operator!=(const floatScalar val) const noexcept { return !operator==(val); } -inline bool Foam::token::operator!=(const doubleScalar val) const +inline bool Foam::token::operator!=(const doubleScalar val) const noexcept { return !operator==(val); } diff --git a/src/OpenFOAM/db/IOstreams/token/tokenIO.C b/src/OpenFOAM/db/IOstreams/token/tokenIO.C index 2cca7d1f296d01703f35a9a812894d66971befe4..da1a39a3cad137469ff3dd1dd1e9c1134a27ee10 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenIO.C +++ b/src/OpenFOAM/db/IOstreams/token/tokenIO.C @@ -92,9 +92,9 @@ static OS& printTokenInfo(OS& os, const token& tok) case token::tokenType::COMPOUND: { - if (tok.compoundToken().empty()) + if (tok.compoundToken().moved()) { - os << "empty "; + os << "moved "; } os << "compound of type " << tok.compoundToken().type(); diff --git a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C index db76bd1b312ff5a0de8b5e06b9f4656b4b85953f..72a06b2bb6811f7dd5bd9612b4f894eb1caf377f 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,43 +70,35 @@ Foam::dictionaryListEntry::dictionaryListEntry dictionary::null ) { - token firstToken(is); - if (firstToken.isLabel()) + token tok(is); + if (tok.isLabel()) { - const label sz = firstToken.labelToken(); + const label len = tok.labelToken(); is.readBeginList("List"); - for (label i=0; i<sz; ++i) + for (label i=0; i<len; ++i) { entry::New(*this, is); } is.readEndList("List"); } - else if - ( - firstToken.isPunctuation() - && firstToken.pToken() == token::BEGIN_LIST - ) + else if (tok.isPunctuation(token::BEGIN_LIST)) { while (true) { - token nextToken(is); - if (nextToken.error()) + is >> tok; + if (tok.error()) { FatalIOErrorInFunction(is) - << "parsing error " << nextToken.info() + << "parsing error " << tok.info() << nl << exit(FatalIOError); } - else if - ( - nextToken.isPunctuation() - && nextToken.pToken() == token::END_LIST - ) + else if (tok.isPunctuation(token::END_LIST)) { break; } - is.putBack(nextToken); + is.putBack(tok); entry::New(*this, is); } } @@ -113,7 +106,7 @@ Foam::dictionaryListEntry::dictionaryListEntry { FatalIOErrorInFunction(is) << "incorrect first token, expected <int> or '(', found " - << firstToken.info() + << tok.info() << nl << exit(FatalIOError); } } diff --git a/src/OpenFOAM/db/dictionary/entry/entryIO.C b/src/OpenFOAM/db/dictionary/entry/entryIO.C index 47670683a16c78dd9137ca58631a8b7545879a41..48a0d9d83a6fa01f7376a92c4ae0b63dd3c4957d 100644 --- a/src/OpenFOAM/db/dictionary/entry/entryIO.C +++ b/src/OpenFOAM/db/dictionary/entry/entryIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -133,11 +133,7 @@ bool Foam::entry::New const bool valid = getKeyword(keyword, keyToken, is); // Can accept a list of entries too - if - ( - keyToken.isLabel() - || (keyToken.isPunctuation() && keyToken.pToken() == token::BEGIN_LIST) - ) + if (keyToken.isLabel() || keyToken.isPunctuation(token::BEGIN_LIST)) { is.putBack(keyToken); return parentDict.add diff --git a/src/OpenFOAM/expressions/exprTools/exprTools.C b/src/OpenFOAM/expressions/exprTools/exprTools.C index 02a5ff3a0789fed9c6ccdec030fe2d262d583a4f..7ce4f220029a9e0ddca6b21c1dcd2c5de2874468 100644 --- a/src/OpenFOAM/expressions/exprTools/exprTools.C +++ b/src/OpenFOAM/expressions/exprTools/exprTools.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -157,29 +157,21 @@ Foam::exprTools::getList ITstream& is = eptr->stream(); - token firstToken(is); + token tok(is); List<string> list; - if - ( - firstToken.isLabel() - || - ( - firstToken.type() == token::PUNCTUATION - && firstToken.pToken() == token::BEGIN_LIST - ) - ) + if (tok.isLabel() || tok.isPunctuation(token::BEGIN_LIST)) { // A list of strings is.rewind(); is >> list; } - else if (firstToken.isString()) + else if (tok.isString()) { // A single string list.resize(1); - list[0] = firstToken.stringToken(); + list[0] = tok.stringToken(); } else { diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index 45bc05f2a8d079941abdbd3953be7a787e8264e6..ba91d0b82befe2c2f0cafc4240fd932bc053f273 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -191,47 +191,35 @@ Foam::Field<Type>::Field // Read first token token firstToken(is); - if (firstToken.isWord()) + if (firstToken.isWord("uniform")) { - if (firstToken.wordToken() == "uniform") - { - this->setSize(len); - operator=(pTraits<Type>(is)); - } - else if (firstToken.wordToken() == "nonuniform") + this->resize(len); + operator=(pTraits<Type>(is)); + } + else if (firstToken.isWord("nonuniform")) + { + is >> static_cast<List<Type>&>(*this); + const label lenRead = this->size(); + if (len != lenRead) { - is >> static_cast<List<Type>&>(*this); - label currentSize = this->size(); - if (currentSize != len) + if (len < lenRead && allowConstructFromLargerSize) { - if (len < currentSize && allowConstructFromLargerSize) - { - #ifdef FULLDEBUG - IOWarningInFunction(dict) - << "Sizes do not match. " - << "Re-sizing " << currentSize - << " entries to " << len - << endl; - #endif - - // Resize the data - this->setSize(len); - } - else - { - FatalIOErrorInFunction(dict) - << "size " << this->size() - << " is not equal to the given value of " << len - << exit(FatalIOError); - } + #ifdef FULLDEBUG + IOWarningInFunction(dict) + << "Sizes do not match. Truncating " << lenRead + << " entries to " << len << endl; + #endif + + // Truncate the data + this->resize(len); + } + else + { + FatalIOErrorInFunction(dict) + << "size " << lenRead + << " is not equal to the expected length " << len + << exit(FatalIOError); } - } - else - { - FatalIOErrorInFunction(dict) - << "Expected keyword 'uniform' or 'nonuniform', found " - << firstToken.wordToken() - << exit(FatalIOError); } } else diff --git a/src/fileFormats/vtk/file/foamVtkSeriesWriter.C b/src/fileFormats/vtk/file/foamVtkSeriesWriter.C index 104127b0623a8e49e25262b3f0c9a59125b84a4f..6185cad622dea50d3bb7462441b6718c977950fb 100644 --- a/src/fileFormats/vtk/file/foamVtkSeriesWriter.C +++ b/src/fileFormats/vtk/file/foamVtkSeriesWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,10 +51,7 @@ namespace Foam return ( // Token 1 = ':' separator - ( - getToken(is, tok) - && tok.isPunctuation() && tok.pToken() == token::COLON - ) + (getToken(is, tok) && tok.isPunctuation(token::COLON)) // Token 2 is the value && getToken(is, tok) @@ -441,8 +438,7 @@ Foam::label Foam::vtk::seriesWriter::load if ( getValueToken(is, tok) - && tok.isPunctuation() - && tok.pToken() == token::BEGIN_SQR + && tok.isPunctuation(token::BEGIN_SQR) ) { state = parse::FILES_ARRAY; diff --git a/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C b/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C index 67ee68439440023ae4adc617e8cf87f9cbdf3bea..fc9f319ccc197df0db52c5a9e5074ba1c2071cde 100644 --- a/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C +++ b/src/genericPatchFields/genericFaPatchField/genericFaPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -97,11 +97,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField // Read first token token firstToken(is); - if - ( - firstToken.isWord() - && firstToken.wordToken() == "nonuniform" - ) + if (firstToken.isWord("nonuniform")) { token fieldToken(is); @@ -306,11 +302,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField << exit(FatalIOError); } } - else if - ( - firstToken.isWord() - && firstToken.wordToken() == "uniform" - ) + else if (firstToken.isWord("uniform")) { token fieldToken(is); @@ -709,8 +701,7 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const ( dEntry.isStream() && dEntry.stream().size() - && dEntry.stream()[0].isWord() - && dEntry.stream()[0].wordToken() == "nonuniform" + && dEntry.stream()[0].isWord("nonuniform") ) { if (scalarFields_.found(key)) diff --git a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C index 1aac7745bbd15d14dba51a46c37864860f928ea5..3ce915e5ec60c21dafea89b83840efd920cd372f 100644 --- a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C +++ b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -97,11 +97,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField // Read first token token firstToken(is); - if - ( - firstToken.isWord() - && firstToken.wordToken() == "nonuniform" - ) + if (firstToken.isWord("nonuniform")) { token fieldToken(is); @@ -306,11 +302,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField << exit(FatalIOError); } } - else if - ( - firstToken.isWord() - && firstToken.wordToken() == "uniform" - ) + else if (firstToken.isWord("uniform")) { token fieldToken(is); @@ -708,8 +700,7 @@ void Foam::genericFvPatchField<Type>::write(Ostream& os) const ( dEntry.isStream() && dEntry.stream().size() - && dEntry.stream()[0].isWord() - && dEntry.stream()[0].wordToken() == "nonuniform" + && dEntry.stream()[0].isWord("nonuniform") ) { if (scalarFields_.found(key)) diff --git a/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C b/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C index bdcfd637bfb854bf16a644f846c7725096796897..8b3af677ff6954fc4785ae89b56b7d425ff56b7c 100644 --- a/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C +++ b/src/genericPatchFields/genericFvsPatchField/genericFvsPatchField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -96,11 +96,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField // Read first token token firstToken(is); - if - ( - firstToken.isWord() - && firstToken.wordToken() == "nonuniform" - ) + if (firstToken.isWord("nonuniform")) { token fieldToken(is); @@ -305,11 +301,7 @@ Foam::genericFvsPatchField<Type>::genericFvsPatchField << exit(FatalIOError); } } - else if - ( - firstToken.isWord() - && firstToken.wordToken() == "uniform" - ) + else if (firstToken.isWord("uniform")) { token fieldToken(is); @@ -708,8 +700,7 @@ void Foam::genericFvsPatchField<Type>::write(Ostream& os) const ( dEntry.isStream() && dEntry.stream().size() - && dEntry.stream()[0].isWord() - && dEntry.stream()[0].wordToken() == "nonuniform" + && dEntry.stream()[0].isWord("nonuniform") ) { if (scalarFields_.found(key)) diff --git a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C index 8a70223bd1b83944cec8425533d68bc7841ef9cf..a4ccaecb18916040a32b275addc51320058284b0 100644 --- a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C +++ b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -77,11 +77,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField // Read first token token firstToken(is); - if - ( - firstToken.isWord() - && firstToken.wordToken() == "nonuniform" - ) + if (firstToken.isWord("nonuniform")) { token fieldToken(is); @@ -490,8 +486,7 @@ void Foam::genericPointPatchField<Type>::write(Ostream& os) const ( dEntry.isStream() && dEntry.stream().size() - && dEntry.stream()[0].isWord() - && dEntry.stream()[0].wordToken() == "nonuniform" + && dEntry.stream()[0].isWord("nonuniform") ) { if (scalarFields_.found(key)) diff --git a/src/lagrangian/basic/IOPosition/IOPosition.C b/src/lagrangian/basic/IOPosition/IOPosition.C index 1af75c19a25b0c5e452afe754d569ab0107302ea..27014dab3a0bdf5aa49899d15d88572af4a97722 100644 --- a/src/lagrangian/basic/IOPosition/IOPosition.C +++ b/src/lagrangian/basic/IOPosition/IOPosition.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -98,18 +98,18 @@ void Foam::IOPosition<CloudType>::readData(Istream& is, CloudType& c) { const polyMesh& mesh = c.pMesh(); - token firstToken(is); + token tok(is); const bool newFormat = (geometryType_ == cloud::geometryType::COORDINATES); - if (firstToken.isLabel()) + if (tok.isLabel()) { - label s = firstToken.labelToken(); + const label len = tok.labelToken(); // Read beginning of contents is.readBeginList(FUNCTION_NAME); - for (label i=0; i<s; i++) + for (label i=0; i<len; ++i) { // Read position only c.append @@ -127,39 +127,27 @@ void Foam::IOPosition<CloudType>::readData(Istream& is, CloudType& c) // Read end of contents is.readEndList(FUNCTION_NAME); } - else if (firstToken.isPunctuation()) + else if (tok.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) + is >> tok; + while (!tok.isPunctuation(token::END_LIST)) { - FatalIOErrorInFunction(is) - << "incorrect first token, '(', found " - << firstToken.info() << exit(FatalIOError); - } - - token lastToken(is); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) - { - is.putBack(lastToken); + is.putBack(tok); // Read position only c.append ( new typename CloudType::particleType(mesh, is, false, newFormat) ); - is >> lastToken; + is >> tok; } } else { FatalIOErrorInFunction(is) << "incorrect first token, expected <int> or '(', found " - << firstToken.info() << exit(FatalIOError); + << tok.info() << nl + << exit(FatalIOError); } is.check(FUNCTION_NAME); diff --git a/src/mesh/blockMesh/blockMesh/blockMeshTopology.C b/src/mesh/blockMesh/blockMesh/blockMeshTopology.C index 994149d53e9901d203ffe1319793fbc920c76e2f..5e3a01fa33c5cb56d2fe7c69d164ae1e3f5ebdc3 100644 --- a/src/mesh/blockMesh/blockMesh/blockMeshTopology.C +++ b/src/mesh/blockMesh/blockMesh/blockMeshTopology.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -139,13 +139,7 @@ void Foam::blockMesh::readPatches nPatches = 0; token lastToken(patchStream); - while - ( - !( - lastToken.isPunctuation() - && lastToken.pToken() == token::END_LIST - ) - ) + while (!lastToken.isPunctuation(token::END_LIST)) { if (tmpBlocksPatches.size() <= nPatches) { diff --git a/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C b/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C index 4118b61b8705c9eedb3466aaddb2eaa9c7647a26..e09b31fd0be6b4e9584a216c9afa4b5fb14ff1e3 100644 --- a/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C +++ b/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,29 +32,29 @@ template<class T> void Foam::blockMeshTools::read ( Istream& is, - List<T>& L, + List<T>& list, const dictionary& dict ) { - token firstToken(is); + token tok(is); - if (firstToken.isLabel()) + if (tok.isLabel()) { - const label s = firstToken.labelToken(); + const label len = tok.labelToken(); // Set list length to that read - L.setSize(s); + list.resize(len); // Read beginning of contents const char delimiter = is.readBeginList("List"); - if (s) + if (len) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i<s; ++i) + for (label i=0; i<len; ++i) { - read(is, L[i], dict); + read(is, list[i], dict); } } } @@ -61,39 +62,33 @@ void Foam::blockMeshTools::read // Read end of contents is.readEndList("List"); } - else if (firstToken.isPunctuation()) + else if (tok.isPunctuation(token::BEGIN_LIST)) { - if (firstToken.pToken() != token::BEGIN_LIST) - { - FatalIOErrorInFunction(is) - << "incorrect first token, expected '(', found " - << firstToken.info() - << exit(FatalIOError); - } - SLList<T> sll; - while (true) + is >> tok; + is.fatalCheck(FUNCTION_NAME); + + while (!tok.isPunctuation(token::END_LIST)) { - token t(is); - if (t.isPunctuation() && t.pToken() == token::END_LIST) - { - break; - } - is.putBack(t); + is.putBack(tok); + T elem; read(is, elem, dict); sll.append(elem); + + is >> tok; + is.fatalCheck(FUNCTION_NAME); } // Convert the singly-linked list to this list - L = sll; + list = std::move(sll); } else { FatalIOErrorInFunction(is) << "incorrect first token, expected <int> or '(', found " - << firstToken.info() + << tok.info() << nl << exit(FatalIOError); } } @@ -106,9 +101,9 @@ Foam::List<T> Foam::blockMeshTools::read const dictionary& dict ) { - List<T> L; - read(is, L, dict); - return L; + List<T> list; + read(is, list, dict); + return list; } diff --git a/src/mesh/blockMesh/blockVertices/blockVertex/blockVertex.C b/src/mesh/blockMesh/blockVertices/blockVertex/blockVertex.C index 05c2809bd3e4684fe07821ca42b30a456c99659d..7f1e99575aba01183e24060db97da18aca502c66 100644 --- a/src/mesh/blockMesh/blockVertices/blockVertex/blockVertex.C +++ b/src/mesh/blockMesh/blockVertices/blockVertex/blockVertex.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,7 +60,7 @@ Foam::autoPtr<Foam::blockVertex> Foam::blockVertex::New token firstToken(is); - if (firstToken.isPunctuation() && firstToken.pToken() == token::BEGIN_LIST) + if (firstToken.isPunctuation(token::BEGIN_LIST)) { // Putback the opening bracket is.putBack(firstToken); @@ -92,7 +92,7 @@ Foam::autoPtr<Foam::blockVertex> Foam::blockVertex::New FatalIOErrorInFunction(is) << "incorrect first token, expected <word> or '(', found " - << firstToken.info() + << firstToken.info() << nl << exit(FatalIOError); return nullptr; diff --git a/src/mesh/blockMesh/gradingDescriptor/gradingDescriptor.C b/src/mesh/blockMesh/gradingDescriptor/gradingDescriptor.C index f3753a8534535a92462159badf5491498b0100fc..e15dcfc2acc066f2bfd49a0d10b17911c119ee32 100644 --- a/src/mesh/blockMesh/gradingDescriptor/gradingDescriptor.C +++ b/src/mesh/blockMesh/gradingDescriptor/gradingDescriptor.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -126,7 +126,7 @@ Foam::Istream& Foam::operator>>(Istream& is, gradingDescriptor& gd) gd.nDivFraction_ = 1.0; gd.expansionRatio_ = t.number(); } - else if (t.isPunctuation() && t.pToken() == token::BEGIN_LIST) + else if (t.isPunctuation(token::BEGIN_LIST)) { is >> gd.blockFraction_ >> gd.nDivFraction_ >> gd.expansionRatio_; is.readEnd("gradingDescriptor"); diff --git a/src/meshTools/PatchFunction1/MappedFile/rawIOField.C b/src/meshTools/PatchFunction1/MappedFile/rawIOField.C index 15e6fdd85e3ddcb2c1cac92e4fad4d151f6b9cf9..efa474708907b5c51cdb881abe7567e8310b0295 100644 --- a/src/meshTools/PatchFunction1/MappedFile/rawIOField.C +++ b/src/meshTools/PatchFunction1/MappedFile/rawIOField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,10 +65,7 @@ Foam::rawIOField<Type>::rawIOField(const IOobject& io, const bool readAverage) const token firstToken(is); - headerOk = - is.good() - && firstToken.isWord() - && firstToken.wordToken() == "FoamFile"; + headerOk = is.good() && firstToken.isWord("FoamFile"); } isPtr.clear(); diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L index b6015483f394eac251d3596a4ad14b6c951eb805..a117a58a85ffeb34c2f9af28f5877fbb1f09642f 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1216,7 +1216,7 @@ bool finishReaction = false; reactionCoeffsString.replaceAll("d", "e"); reactionCoeffsString.replaceAll("D", "e"); IStringStream reactionCoeffsStream(reactionCoeffsString); - reactionCoeffsStream.lineNumber() = lineNo_; + reactionCoeffsStream.lineNumber(lineNo_); reactionCoeffsStream >> ArrheniusCoeffs[0]