diff --git a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C index d5477c7a9e..70d5904aa0 100644 --- a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C +++ b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C @@ -73,9 +73,11 @@ Foam::label Foam::mergePolyMesh::patchIndex(const polyPatch& p) // Patch not found. Append to the list { - OStringStream os; + OCharStream os; p.write(os); - patchDicts_.append(dictionary(IStringStream(os.str())())); + ISpanStream is(os.view()); + + patchDicts_.push_back(dictionary(is)); } if (nameFound) @@ -225,13 +227,15 @@ Foam::mergePolyMesh::mergePolyMesh(const IOobject& io) // Insert the original patches into the list wordList curPatchNames = boundaryMesh().names(); + OCharStream os; forAll(boundaryMesh(), patchi) { - patchNames_.append(boundaryMesh()[patchi].name()); - - OStringStream os; + os.rewind(); boundaryMesh()[patchi].write(os); - patchDicts_.append(dictionary(IStringStream(os.str())())); + ISpanStream is(os.view()); + + patchNames_.push_back(boundaryMesh()[patchi].name()); + patchDicts_.push_back(dictionary(is)); } // Insert point, face and cell zones into the list diff --git a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C index ebfef7d84a..899ce6ccb7 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C +++ b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C @@ -143,17 +143,10 @@ void createFieldFiles dictionary field; - fileName regionPath = "/"; - - if (!regionName.empty()) - { - regionPath += regionName + '/'; - } - field.add ( "#include", - "$FOAM_CASE/system" + regionPath + "caseProperties" + ""/regionName/"caseProperties" ); field.add("dimensions", fieldDimensions[i]); @@ -173,15 +166,22 @@ void createFieldFiles // Expand all of the dictionary redirections and remove unnecessary // entries - OStringStream os; - os << field; - entry::disableFunctionEntries = 0; - dictionary field2(IStringStream(os.str())()); - entry::disableFunctionEntries = 1; - field2.remove("#include"); - field2.remove("initialConditions"); - field2.remove("boundaryConditions"); + dictionary field2; + + { + OCharStream os; + os << field; + ISpanStream is(os.view()); + + entry::disableFunctionEntries = 0; + is >> field2; + entry::disableFunctionEntries = 1; + + field2.remove("#include"); + field2.remove("initialConditions"); + field2.remove("boundaryConditions"); + } // Construct and write field dictionary. Note use of localIOdictionary localIOdictionary fieldOut @@ -192,7 +192,9 @@ void createFieldFiles "0", regionName, runTime, - IOobject::NO_READ + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER ), field2 ); @@ -235,7 +237,8 @@ int main(int argc, char *argv[]) runTime.system(), runTime, IOobject::MUST_READ, - IOobject::NO_WRITE + IOobject::NO_WRITE, + IOobject::NO_REGISTER ) ); diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C index 5d30a193e8..0d29eaecf7 100644 --- a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C +++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C @@ -99,9 +99,11 @@ int main(int argc, char *argv[]) // Temporary hack to splice the specie composition data into the thermo file // pending complete integration into the thermodynamics structure - OStringStream os; + OCharStream os; cr.speciesThermo().write(os); - dictionary thermoDict(IStringStream(os.str())()); + + ISpanStream is(os.view()); + dictionary thermoDict(is); // Add elements for (entry& dEntry : thermoDict) diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index d471ad7f55..778666aca9 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -207,7 +207,7 @@ void Foam::Time::readDict() // Change in-memory dimensionedConstants().merge(*localDict); - IStringStream dummyIs(""); + ISpanStream dummyIs; // Reporting verbosity corresponding to detail level const bool verbose = (::Foam::infoDetailLevel > 0); @@ -255,11 +255,14 @@ void Foam::Time::readDict() const List& objects = *objPtr; + OCharStream os; + for (simpleRegIOobject* obj : objects) { - OStringStream os; + os.rewind(); os << dict; - IStringStream is(os.str()); + + ISpanStream is(os.view()); obj->readData(is); } } diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 68d1487899..024713199a 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -241,7 +241,7 @@ Foam::SHA1Digest Foam::dictionary::digest() const Foam::tokenList Foam::dictionary::tokens() const { // Serialize dictionary entries into a string - OStringStream os; + OCharStream os; // Process entries for (const entry& e : *this) @@ -250,7 +250,7 @@ Foam::tokenList Foam::dictionary::tokens() const } // String re-parsed as a list of tokens - return ITstream::parse(os.str()); + return ITstream::parse(os.view()); } diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index c82da030cc..4554c48bd5 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ License #include "entry.H" #include "dictionary.H" -#include "StringStream.H" +#include "SpanStream.H" #include "JobInfo.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -206,14 +206,23 @@ bool Foam::entry::operator==(const entry& e) const } // Compare contents (as strings) + OCharStream content1; + content1 << *this; - OStringStream oss1; - oss1 << *this; + OCharStream content2; + content2 << e; - OStringStream oss2; - oss2 << e; - - return oss1.str() == oss2.str(); + return + ( + content1.view().size() == content2.view().size() + && + std::equal + ( + content1.view().begin(), + content1.view().end(), + content2.view().begin() + ) + ); } diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C index 0342274870..61be70d4e0 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,7 +28,8 @@ License #include "primitiveEntry.H" #include "dictionary.H" -#include "StringStream.H" +#include "SpanStream.H" +#include "StringStream.H" // Legacy include, perhaps expected elsewhere // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -37,9 +39,9 @@ Foam::primitiveEntry::primitiveEntry(const keyType& key, const T& val) entry(key), ITstream(IOstreamOption(), key) { - OStringStream os; + OCharStream os; os << val << token::END_STATEMENT; - IStringStream is(os.str()); + ISpanStream is(os.view()); readEntry(dictionary::null, is); } diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C index b289adb034..69bef4e188 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C @@ -237,9 +237,9 @@ Foam::codedFixedValuePointPatchField::redirectPatchField() const // Construct a patch // Make sure to construct the patchfield with up-to-date value - OStringStream os; + OCharStream os; this->writeValueEntry(os); - IStringStream is(os.str()); + ISpanStream is(os.view()); dictionary constructDict(is); constructDict.set("type", name_); diff --git a/src/OpenFOAM/global/debug/simpleObjectRegistry.C b/src/OpenFOAM/global/debug/simpleObjectRegistry.C index 5636a7bca5..4b032b3570 100644 --- a/src/OpenFOAM/global/debug/simpleObjectRegistry.C +++ b/src/OpenFOAM/global/debug/simpleObjectRegistry.C @@ -28,6 +28,7 @@ License #include "simpleObjectRegistry.H" #include "dictionary.H" #include "ITstream.H" +#include "SpanStream.H" #include "StringStream.H" #include "int.H" #include "floatScalar.H" @@ -57,11 +58,15 @@ void Foam::simpleObjectRegistry::setValues const List& objects = *objPtr; + OCharStream os; + ISpanStream is; + if (dEntry.isDict()) { - OStringStream os; - os << dEntry.dict(); - IStringStream is(os.str()); + os.rewind(); + os << dEntry.dict(); + + is.reset(os.view()); // Or alternatively? // ITstream is(dEntry.dict().tokens()); @@ -72,7 +77,7 @@ void Foam::simpleObjectRegistry::setValues obj->readData(is); } } - else + else // dEntry.isStream() { for (simpleRegIOobject* obj : objects) { diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C index d11a9478bb..c70c8242e1 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C @@ -121,16 +121,22 @@ Foam::GAMGSolver::GAMGSolver ( dummyPrimMeshInterfaces.size() ); + + OCharStream os(IOstreamOption::BINARY); + ISpanStream is(IOstreamOption::BINARY); + forAll(fineMeshInterfaces, intI) { if (fineMeshInterfaces.set(intI)) { - OStringStream os(IOstreamOption::BINARY); + os.rewind(); + refCast ( fineMeshInterfaces[intI] ).write(os); - IStringStream is(os.str(), IOstreamOption::BINARY); + + is.reset(os.view()); dummyPrimMeshInterfaces.set ( diff --git a/src/fileFormats/vtk/read/vtkUnstructuredReader.C b/src/fileFormats/vtk/read/vtkUnstructuredReader.C index 52e6ca8cc2..40b45b37e7 100644 --- a/src/fileFormats/vtk/read/vtkUnstructuredReader.C +++ b/src/fileFormats/vtk/read/vtkUnstructuredReader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2016 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -888,7 +888,8 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile) { string line; inFile.getLine(line); - IStringStream is(line); + ISpanStream is(line); + word dataName(is); word dataType(is); //label numComp(readLabel(inFile)); @@ -923,7 +924,8 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile) // 'NORMALS Normals float' string line; inFile.getLine(line); - IStringStream is(line); + ISpanStream is(line); + word dataName(is); word dataType(is); DebugInfo @@ -971,7 +973,8 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile) // 'TEXTURE_COORDINATES TCoords 2 float' string line; inFile.getLine(line); - IStringStream is(line); + ISpanStream is(line); + word dataName(is); //"Tcoords" label dim(readLabel(is)); word dataType(is); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index fad36642e6..eaf2de2de4 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -237,9 +237,9 @@ Foam::codedFixedValueFvPatchField::redirectPatchField() const // Construct a patch // Make sure to construct the patchfield with up-to-date value - OStringStream os; + OCharStream os; this->writeValueEntry(os); - IStringStream is(os.str()); + ISpanStream is(os.view()); dictionary constructDict(is); constructDict.set("type", name_); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C index c63ebc4abc..33e41351ba 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C @@ -228,10 +228,9 @@ Foam::codedMixedFvPatchField::redirectPatchField() const // Make sure to construct the patchfield with up-to-date value // Write the data from the mixed b.c. - OStringStream os; + OCharStream os; this->parent_bctype::write(os); - IStringStream is(os.str()); - // Construct dictionary from it. + ISpanStream is(os.view()); dictionary constructDict(is); // Override type diff --git a/src/mesh/blockMesh/blockMesh/blockMesh.C b/src/mesh/blockMesh/blockMesh/blockMesh.C index da0f958eb5..23dd0382d4 100644 --- a/src/mesh/blockMesh/blockMesh/blockMesh.C +++ b/src/mesh/blockMesh/blockMesh/blockMesh.C @@ -352,12 +352,16 @@ Foam::PtrList Foam::blockMesh::patchDicts() const PtrList patchDicts(topoPatches.size()); + OCharStream os; + ISpanStream is; + forAll(topoPatches, patchi) { - OStringStream os; + os.rewind(); topoPatches[patchi].write(os); - IStringStream is(os.str()); - patchDicts.set(patchi, new dictionary(is)); + + is.reset(os.view()); + patchDicts.emplace_set(patchi, is); } return patchDicts; } diff --git a/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C b/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C index 6baafddc76..bdcc8773b9 100644 --- a/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C +++ b/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C @@ -81,9 +81,11 @@ Foam::solidReaction::solidReaction glhs_(), grhs_() { + ICharStream reactionIs(dict.getString("reaction")); + this->setLRhs ( - IStringStream(dict.getString("reaction"))(), + reactionIs, pyrolisisGases_, glhs_, grhs_, @@ -99,9 +101,10 @@ Foam::solidReaction::solidReaction List dummyRhs; // Rescan (and fail) if a species is neither gas nor solid + reactionIs.rewind(); this->setLRhs ( - IStringStream(dict.getString("reaction"))(), + reactionIs, allSpecies, dummyLhs, dummyRhs diff --git a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C index ad096ee103..af8e6ce523 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C +++ b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C @@ -332,9 +332,11 @@ Foam::Reaction::Reaction name_(dict.dictName()), species_(species) { + ICharStream reactionIs(dict.getString("reaction")); + setLRhs ( - IStringStream(dict.getString("reaction"))(), + reactionIs, species_, lhs_, rhs_,