diff --git a/applications/test/ICharStream1/Test-ICharStream1.cxx b/applications/test/ICharStream1/Test-ICharStream1.cxx index 97853911c7..c0bcaa08c7 100644 --- a/applications/test/ICharStream1/Test-ICharStream1.cxx +++ b/applications/test/ICharStream1/Test-ICharStream1.cxx @@ -89,12 +89,6 @@ Ostream& printView(Ostream& os, std::string_view s) } -Ostream& printView(Ostream& os, stdFoam::span s) -{ - return printView(os, s.begin(), s.end()); -} - - Ostream& printView(Ostream& os, const UList& list) { return printView(os, list.begin(), list.end()); diff --git a/applications/test/OCharStream1/Test-OCharStream1.cxx b/applications/test/OCharStream1/Test-OCharStream1.cxx index 7499b9c04a..b5def1b8fa 100644 --- a/applications/test/OCharStream1/Test-OCharStream1.cxx +++ b/applications/test/OCharStream1/Test-OCharStream1.cxx @@ -89,12 +89,6 @@ Ostream& printView(Ostream& os, std::string_view s) } -Ostream& printView(Ostream& os, stdFoam::span s) -{ - return printView(os, s.begin(), s.end()); -} - - Ostream& printView(Ostream& os, const UList& list) { return printView(os, list.begin(), list.end()); diff --git a/applications/test/OCountStream/Test-OCountStream.cxx b/applications/test/OCountStream/Test-OCountStream.cxx index 1d073efe43..8722c78ed8 100644 --- a/applications/test/OCountStream/Test-OCountStream.cxx +++ b/applications/test/OCountStream/Test-OCountStream.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,7 +65,6 @@ int main(int argc, char *argv[]) OCountStream cnt; OCharStream cstr; - OStringStream sstr; ocountstream plain; generateOutput(cstr); @@ -77,7 +76,6 @@ int main(int argc, char *argv[]) Info<< "counter state: " << (cnt.stdStream().rdstate()) << nl << "via char-stream: " << label(cstr.view().size()) << " chars" << nl - << "via string-stream: " << label(sstr.count()) << " chars" << nl << "via ocountstream: " << plain.count() << " chars" << endl; fileName outputName; diff --git a/applications/test/SpanStream1/Test-SpanStream1.cxx b/applications/test/SpanStream1/Test-SpanStream1.cxx index 6e6e988b14..7282294dfc 100644 --- a/applications/test/SpanStream1/Test-SpanStream1.cxx +++ b/applications/test/SpanStream1/Test-SpanStream1.cxx @@ -91,12 +91,6 @@ Ostream& printView(Ostream& os, std::string_view s) } -Ostream& printView(Ostream& os, stdFoam::span s) -{ - return printView(os, s.begin(), s.end()); -} - - Ostream& printView(Ostream& os, const UList& list) { return printView(os, list.begin(), list.end()); diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C index 889b2e19f6..d38489a5f0 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C @@ -71,6 +71,26 @@ bool Foam::IOstream::fatalCheck(const char* operation) const } +bool Foam::IOstream::fatalCheckNativeSizes(const char* operation) const +{ + const bool ok = this->checkNativeSizes(); + + if (!ok) + { + FatalIOErrorInFunction(*this) + << "Error in stream: " << relativeName() + << " for operation " << operation << nl + << "Expecting (label=" << (8*sizeof(label)) + << ";scalar=" << (8*sizeof(scalar)) + << ") found (label=" << (8*this->labelByteSize()) + << ";scalar=" << (8*this->scalarByteSize()) << ')' << nl + << exit(FatalIOError); + } + + return ok; +} + + void Foam::IOstream::print(Ostream& os) const { os << "IOstream: " << "Version " << version() << ", format " diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index 9ea252620d..61e6010b75 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -297,7 +297,7 @@ public: } - //- Check if the label byte-size associated with the stream + //- Test if the label byte-size associated with the stream //- is the same as the given type template std::enable_if_t, bool> @@ -306,7 +306,7 @@ public: return sizeofLabel_ == sizeof(T); } - //- Check if the scalar byte-size associated with the stream + //- Test if the scalar byte-size associated with the stream //- is the same as the given type template std::enable_if_t, bool> @@ -315,6 +315,22 @@ public: return sizeofScalar_ == sizeof(T); } + //- Test if the label/scalar byte-size associated with the stream + //- are the native label/scalar sizes + bool checkNativeSizes() const noexcept + { + return + ( + sizeofLabel_ == sizeof(label) + && sizeofScalar_ == sizeof(scalar) + ); + } + + //- Assert that the label/scalar byte-size associated with the stream + //- are the native label/scalar sizes. + // Generate a FatalIOError for any mismatch. + bool fatalCheckNativeSizes(const char* operation) const; + // Stream State Functions diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H index 63089e40e9..0950df267a 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H @@ -215,9 +215,6 @@ public: // Member Functions - //- The number of bytes outputted - std::streamsize count() { return stream_.tellp(); } - //- Get the string. //- As Foam::string instead of std::string (may change in future) Foam::string str() const { return Foam::string(stream_.str()); } diff --git a/src/OpenFOAM/db/IOstreams/memory/ICharStream.H b/src/OpenFOAM/db/IOstreams/memory/ICharStream.H index 866a7d2135..24f79b564f 100644 --- a/src/OpenFOAM/db/IOstreams/memory/ICharStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/ICharStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2024 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -141,8 +141,8 @@ public: ); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(buffer_type::view()) + //- A string_view of buffer contents + auto view() const { return buffer_type::view(); } @@ -290,15 +290,15 @@ public: //- Span of the input characters (is modifiable!) UList list() const { return stream_.list(); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(stream_.view()) + //- A string_view of buffer contents + auto view() const { return stream_.view(); } //- For IStringStream compatibility, return the buffer as string copy. // Use sparingly - it creates a full copy!! - auto str() const -> decltype(stream_.str()) + auto str() const { return stream_.str(); } diff --git a/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H b/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H index f8b2adba15..f18b264d75 100644 --- a/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H @@ -169,8 +169,8 @@ public: ); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(buffer_type::view()) + //- A string_view of buffer contents + auto view() const { return buffer_type::view(); } @@ -351,15 +351,15 @@ public: //- Span of the current input characters (is modifiable!) UList list() const { return stream_.list(); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(stream_.view()) + //- A string_view of buffer contents + auto view() const { return stream_.view(); } //- For IStringStream compatibility, return the buffer as string copy. // Use sparingly - it creates a full copy!! - auto str() const -> decltype(stream_.str()) + auto str() const { return stream_.str(); } diff --git a/src/OpenFOAM/db/IOstreams/memory/OCharStream.H b/src/OpenFOAM/db/IOstreams/memory/OCharStream.H index 8849c4a55d..8a51b127b1 100644 --- a/src/OpenFOAM/db/IOstreams/memory/OCharStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/OCharStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2024 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -147,8 +147,8 @@ public: ); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(buffer_type::view()) + //- A string_view of buffer contents + auto view() const { return buffer_type::view(); } @@ -273,15 +273,15 @@ public: //- Span of the current output characters (is modifiable!) UList list() const { return stream_.list(); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(stream_.view()) + //- A string_view of buffer contents + auto view() const { return stream_.view(); } //- For OStringStream compatibility, return the buffer as string copy. // Use sparingly - it creates a full copy!! - auto str() const -> decltype(stream_.str()) + auto str() const { return stream_.str(); } diff --git a/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H b/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H index 4da824f41a..d13f7f4ba8 100644 --- a/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H @@ -162,8 +162,8 @@ public: ); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(buffer_type::view()) + //- A string_view of buffer contents + auto view() const { return buffer_type::view(); } @@ -305,15 +305,15 @@ public: //- Span of the current output characters (is modifiable!) UList list() const { return stream_.list(); } - //- A string_view (c++17) or span view (older c++) of buffer contents - auto view() const -> decltype(stream_.view()) + //- A string_view of buffer contents + auto view() const { return stream_.view(); } //- For OStringStream compatibility, return buffer as string copy. // Use sparingly - it creates a full copy!! - auto str() const -> decltype(stream_.str()) + auto str() const { return stream_.str(); } diff --git a/src/dynamicMesh/meshCut/wallLayerCells/wallNormalInfo/wallNormalInfo.C b/src/dynamicMesh/meshCut/wallLayerCells/wallNormalInfo/wallNormalInfo.C index f593958bbe..98885258ee 100644 --- a/src/dynamicMesh/meshCut/wallLayerCells/wallNormalInfo/wallNormalInfo.C +++ b/src/dynamicMesh/meshCut/wallLayerCells/wallNormalInfo/wallNormalInfo.C @@ -64,9 +64,9 @@ Foam::Istream& Foam::operator>> { is >> rhs.normal_; } - else if (!is.checkLabelSize<>() || !is.checkScalarSize<>()) + else if (!is.checkScalarSize<>()) { - // Non-native label or scalar size + // Non-native scalar size is.beginRawRead(); readRawScalar(is, rhs.normal_.data(), vector::nComponents); diff --git a/src/functionObjects/utilities/foamReport/substitutionModels/dictionaryValue/dictionaryValue.C b/src/functionObjects/utilities/foamReport/substitutionModels/dictionaryValue/dictionaryValue.C index d754ff598c..ca5f667974 100644 --- a/src/functionObjects/utilities/foamReport/substitutionModels/dictionaryValue/dictionaryValue.C +++ b/src/functionObjects/utilities/foamReport/substitutionModels/dictionaryValue/dictionaryValue.C @@ -5,7 +5,7 @@ \ / A nd | www.openfoam.com \/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2024 OpenCFD Ltd. + Copyright (C) 2024-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,7 +53,7 @@ bool Foam::substitutionModels::dictionaryValue::processDict { const string& lookup = entries_[key]; - OStringStream oss; + OCharStream oss; if (lookup.empty()) { // Add complete dictionary @@ -216,4 +216,4 @@ Foam::wordList Foam::substitutionModels::dictionaryValue::keys() const } -// ************************************************************************* // \ No newline at end of file +// ************************************************************************* // diff --git a/src/functionObjects/utilities/foamReport/substitutionModels/fileRegEx/fileRegEx.C b/src/functionObjects/utilities/foamReport/substitutionModels/fileRegEx/fileRegEx.C index 37fc3f0d68..449c3137c3 100644 --- a/src/functionObjects/utilities/foamReport/substitutionModels/fileRegEx/fileRegEx.C +++ b/src/functionObjects/utilities/foamReport/substitutionModels/fileRegEx/fileRegEx.C @@ -5,7 +5,7 @@ \ / A nd | www.openfoam.com \/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2024 OpenCFD Ltd. + Copyright (C) 2024-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -124,15 +124,15 @@ bool Foam::substitutionModels::fileRegEx::apply Info<< "Cached " << lines.size() << " lines" << endl; - OStringStream oss; - regExp re(entries_[key].c_str()); + OCharStream oss; + const regExp re(entries_[key].c_str()); for (const string& data : lines) { regExp::results_type match; if (re.match(data, match)) { - oss.reset(); + oss.rewind(); for (size_t i = 1; i < match.size(); ++i) { @@ -160,4 +160,4 @@ Foam::wordList Foam::substitutionModels::fileRegEx::keys() const } -// ************************************************************************* // \ No newline at end of file +// ************************************************************************* //