diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointer.H b/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointer.H index ce94bcd6ff..e3c9890793 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointer.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointer.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020-2023 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -132,7 +132,7 @@ public: // Member Functions //- True if compiled with libz support - static bool supports_gz(); + static bool supports_gz() noexcept; // Access @@ -276,7 +276,7 @@ public: // Member Functions //- True if compiled with libz support - static bool supports_gz(); + static bool supports_gz() noexcept; // Access diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointers.C b/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointers.C index 2f69d064f3..89cb40857b 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointers.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/fstreamPointers.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,7 +40,7 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -bool Foam::ifstreamPointer::supports_gz() +bool Foam::ifstreamPointer::supports_gz() noexcept { #ifdef HAVE_LIBZ return true; @@ -50,7 +50,7 @@ bool Foam::ifstreamPointer::supports_gz() } -bool Foam::ofstreamPointer::supports_gz() +bool Foam::ofstreamPointer::supports_gz() noexcept { #ifdef HAVE_LIBZ return true; @@ -71,7 +71,7 @@ Foam::ifstreamPointer::ifstreamPointer IOstreamOption streamOpt // Currently unused ) : - ptr_(nullptr) + ptr_() { open(pathname, streamOpt); } @@ -82,7 +82,7 @@ Foam::ifstreamPointer::ifstreamPointer const fileName& pathname ) : - ptr_(nullptr) + ptr_() { open(pathname); } @@ -110,7 +110,7 @@ Foam::ofstreamPointer::ofstreamPointer const bool atomic ) : - ptr_(nullptr), + ptr_(), atomic_(atomic) { std::ios_base::openmode mode diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index b05e073cb3..5f5ecc8a94 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -468,6 +468,41 @@ inline IOstream& scientific(IOstream& io) namespace Detail { +/*---------------------------------------------------------------------------*\ + Class Detail::StreamAllocator Declaration +\*---------------------------------------------------------------------------*/ + +//- A wrapper to hold a std::stream type for OpenFOAM wrapped streams. +//- This is necessary since the OpenFOAM streams hold a reference to +//- the normal std::stream +template +class StreamAllocator +{ +protected: + + // Protected Data + + //- The std::stream + StreamType stream_; + + + // Constructors + + //- Default construct (empty) + StreamAllocator() = default; +}; + + +} // End namespace Detail + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Functions/Algorithms + +namespace Detail +{ + //- Termination for input looping (no-op) template inline void inputLoop(IS&) {} diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H index 66d766562f..0950df267a 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,60 +46,6 @@ SourceFiles namespace Foam { -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::StringStreamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- Allocator for variants of a std stringstream -template -class StringStreamAllocator -{ -protected: - - // Protected Member Data - - //- The stream type - typedef StreamType stream_type; - - //- The input/output stream. - stream_type stream_; - - - // Constructors - - //- Default construct - StringStreamAllocator() = default; - - //- Copy construct from string - StringStreamAllocator(const std::string& s) - : - stream_(s) - {} - - -public: - - // Member Functions - - //- Get the string - as Foam::string rather than std::string - Foam::string str() const - { - return Foam::string(stream_.str()); - } - - //- Set the string - void str(const std::string& s) - { - stream_.str(s); - } -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class IStringStream Declaration \*---------------------------------------------------------------------------*/ @@ -107,10 +53,12 @@ public: //- Input from string buffer, using a ISstream. Always UNCOMPRESSED. class IStringStream : - public Detail::StringStreamAllocator, - public ISstream + public Foam::Detail::StreamAllocator, + public Foam::ISstream { - typedef Detail::StringStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: @@ -133,9 +81,11 @@ public: IOstreamOption streamOpt = IOstreamOption() ) : - allocator_type(s), + allocator_type(), ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) - {} + { + stream_.str(s); + } //- Construct from char* explicit IStringStream @@ -144,20 +94,32 @@ public: IOstreamOption streamOpt = IOstreamOption() ) : - allocator_type(s), + allocator_type(), ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) - {} + { + stream_.str(s); + } //- Copy construct, copies content and format IStringStream(const IStringStream& str) : - allocator_type(str.str()), + allocator_type(), ISstream(stream_, str.name(), static_cast(str)) - {} + { + stream_.str(str.str()); + } // Member Functions + //- Get the string. + //- As Foam::string instead of std::string (may change in future) + Foam::string str() const { return Foam::string(stream_.str()); } + + //- Set the string + void str(const std::string& s) { stream_.str(s); } + + //- Reset the input buffer and rewind the stream virtual void reset(const std::string& s) { @@ -220,10 +182,12 @@ public: //- Output to string buffer, using a OSstream. Always UNCOMPRESSED. class OStringStream : - public Detail::StringStreamAllocator, - public OSstream + public Foam::Detail::StreamAllocator, + public Foam::OSstream { - typedef Detail::StringStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: @@ -242,13 +206,23 @@ public: //- Copy construct, copies content and format OStringStream(const OStringStream& str) : - allocator_type(str.str()), + allocator_type(), OSstream(stream_, str.name(), static_cast(str)) - {} + { + stream_.str(str.str()); + } // Member Functions + //- Get the string. + //- As Foam::string instead of std::string (may change in future) + Foam::string str() const { return Foam::string(stream_.str()); } + + //- Set the string + void str(const std::string& s) { stream_.str(s); } + + //- Reset the output buffer and rewind the stream void reset() { diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 2a8e1d676e..618bbf3bc9 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -91,13 +91,14 @@ Foam::ITstream& Foam::ITstream::empty_stream() } -Foam::tokenList Foam::ITstream::parse +Foam::tokenList Foam::ITstream::parse_chars ( - const UList& input, + const char* s, + size_t nbytes, IOstreamOption streamOpt ) { - ISpanStream is(input, streamOpt); + ISpanStream is(s, nbytes, streamOpt); tokenList tokens; parseStream(is, tokens); @@ -105,31 +106,14 @@ Foam::tokenList Foam::ITstream::parse } -Foam::tokenList Foam::ITstream::parse -( - const std::string& input, - IOstreamOption streamOpt -) +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::ITstream::reset(const char* input, size_t nbytes) { - ISpanStream is(input, streamOpt); + ISpanStream is(input, nbytes, static_cast(*this)); - tokenList tokens; - parseStream(is, tokens); - return tokens; -} - - -Foam::tokenList Foam::ITstream::parse -( - const char* input, - IOstreamOption streamOpt -) -{ - ISpanStream is(input, strlen(input), streamOpt); - - tokenList tokens; - parseStream(is, tokens); - return tokens; + parseStream(is, static_cast(*this)); + ITstream::seek(0); // rewind(), but bypasss virtual } @@ -254,10 +238,7 @@ Foam::ITstream::ITstream : ITstream(streamOpt, name) { - ISpanStream is(input, streamOpt); - - parseStream(is, static_cast(*this)); - ITstream::seek(0); // rewind(), but bypasss virtual + reset(input.cdata(), input.size_bytes()); } @@ -270,10 +251,7 @@ Foam::ITstream::ITstream : ITstream(streamOpt, name) { - ISpanStream is(input, streamOpt); - - parseStream(is, static_cast(*this)); - ITstream::seek(0); // rewind(), but bypasss virtual + reset(input.data(), input.size()); } @@ -286,10 +264,7 @@ Foam::ITstream::ITstream : ITstream(streamOpt, name) { - ISpanStream is(input, strlen(input), streamOpt); - - parseStream(is, static_cast(*this)); - ITstream::seek(0); // rewind(), but bypasss virtual + reset(input, strlen(input)); } diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index 4cc396c52c..480878bd37 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -77,6 +77,18 @@ class ITstream // but leave any excess capacity (ie, like reserve). void reserveCapacity(const label newCapacity); + //- Convert input sequence into a list of tokens, + static tokenList parse_chars + ( + const char* s, + size_t nbytes, + IOstreamOption streamOpt + ); + + //- Convert input sequence into a list of tokens, + //- using the existing stream format. Rewinds the stream + void reset(const char* input, size_t nbytes); + //- Failsafe read-access to token at specified location //- or undefinedToken inline const token& peekNoFail(const label i) const @@ -158,6 +170,47 @@ public: const string& name = "input" ); + #if __cplusplus >= 201703L + //- Construct token list by parsing the input character sequence + // Uses static parse function internally. + explicit ITstream + ( + std::string_view s, + IOstreamOption streamOpt = IOstreamOption() + ) + : + ITstream(streamOpt) + { + reset(s.data(), s.size()); + } + #endif + + //- Construct token list by parsing the input character sequence + // Uses static parse function internally. + explicit ITstream + ( + stdFoam::span s, + IOstreamOption streamOpt = IOstreamOption() + ) + : + ITstream(streamOpt) + { + reset(s.data(), s.size()); + } + + //- Construct token list by parsing the input character sequence + // Uses static parse function internally. + explicit ITstream + ( + stdFoam::span s, + IOstreamOption streamOpt = IOstreamOption() + ) + : + ITstream(streamOpt) + { + reset(s.data(), s.size()); + } + // Additional constructors @@ -207,7 +260,10 @@ public: ( const UList& input, IOstreamOption streamOpt = IOstreamOption() - ); + ) + { + return parse_chars(input.cdata(), input.size(), streamOpt); + } //- Create token list by parsing the input string //- until no good tokens remain. @@ -215,7 +271,10 @@ public: ( const std::string& input, IOstreamOption streamOpt = IOstreamOption() - ); + ) + { + return parse_chars(input.data(), input.size(), streamOpt); + } //- Create token list by parsing the input character sequence //- until no good tokens remain. @@ -223,7 +282,45 @@ public: ( const char* input, IOstreamOption streamOpt = IOstreamOption() - ); + ) + { + return parse_chars(input, strlen(input), streamOpt); + } + + #if __cplusplus >= 201703L + //- Create token list by parsing the input character sequence + //- until no good tokens remain. + static tokenList parse + ( + std::string_view s, + IOstreamOption streamOpt = IOstreamOption() + ) + { + return parse_chars(s.data(), s.size(), streamOpt); + } + #endif + + //- Create token list by parsing the input character sequence + //- until no good tokens remain. + static tokenList parse + ( + stdFoam::span s, + IOstreamOption streamOpt = IOstreamOption() + ) + { + return parse_chars(s.data(), s.size(), streamOpt); + } + + //- Create token list by parsing the input character sequence + //- until no good tokens remain. + static tokenList parse + ( + stdFoam::span s, + IOstreamOption streamOpt = IOstreamOption() + ) + { + return parse_chars(s.data(), s.size(), streamOpt); + } // Member Functions diff --git a/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H b/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H index 69491d2b90..623f34d30d 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H +++ b/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ Description #ifndef Foam_OSHA1stream_H #define Foam_OSHA1stream_H -#include "OSstream.H" #include "SHA1.H" +#include "OSstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -114,33 +114,6 @@ public: }; -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::OSHA1streamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- An allocator for holding Foam::osha1stream -class OSHA1streamAllocator -{ -protected: - - // Protected Data - - //- The output stream - Foam::osha1stream stream_; - - - // Constructors - - //- Default construct - OSHA1streamAllocator() = default; -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class OSHA1stream Declaration \*---------------------------------------------------------------------------*/ @@ -148,10 +121,12 @@ protected: //- The output stream for calculating SHA1 digests class OSHA1stream : - public Detail::OSHA1streamAllocator, - public OSstream + public Foam::Detail::StreamAllocator, + public Foam::OSstream { - typedef Detail::OSHA1streamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: diff --git a/src/OpenFOAM/db/IOstreams/memory/ICharStream.H b/src/OpenFOAM/db/IOstreams/memory/ICharStream.H index c242b9d08d..866a7d2135 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-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,8 +42,6 @@ See Also #define Foam_ICharStream_H #include "ISpanStream.H" -#include "List.H" -#include "DynamicList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -205,33 +203,6 @@ public: }; -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::ICharStreamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- An allocator for holding Foam::icharstream -class ICharStreamAllocator -{ -protected: - - // Protected Data - - //- The stream - Foam::icharstream stream_; - - - // Constructors - - //- Default construct - ICharStreamAllocator() = default; -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class ICharStream Declaration \*---------------------------------------------------------------------------*/ @@ -239,10 +210,12 @@ protected: //- An ISstream with internal List storage. Always UNCOMPRESSED. class ICharStream : - public Detail::ICharStreamAllocator, + public Foam::Detail::StreamAllocator, public Foam::ISstream { - typedef Detail::ICharStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: diff --git a/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H b/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H index 8f89db282c..9b03bf7bbd 100644 --- a/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/ISpanStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,7 +65,6 @@ See Also #define Foam_ISpanStream_H #include "memoryStreamBuffer.H" -#include "UList.H" #include "ISstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -213,49 +212,23 @@ public: //- Some information about the input buffer position/capacity void debug_info(Ostream& os) const { - os << "get=" - << input_pos() << '/' << capacity(); + os << "get=" << input_pos() << '/' << capacity(); } }; -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::ISpanStreamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- An allocator for holding Foam::ispanstream -class ISpanStreamAllocator -{ -protected: - - // Protected Data - - //- The stream - Foam::ispanstream stream_; - - - // Constructors - - //- Default construct (empty) - ISpanStreamAllocator() = default; -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class ISpanStream Declaration \*---------------------------------------------------------------------------*/ class ISpanStream : - public Detail::ISpanStreamAllocator, + public Foam::Detail::StreamAllocator, public Foam::ISstream { - typedef Detail::ISpanStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: diff --git a/src/OpenFOAM/db/IOstreams/memory/OCharStream.H b/src/OpenFOAM/db/IOstreams/memory/OCharStream.H index 9b45472eae..8849c4a55d 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-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,7 +109,13 @@ public: //- The current output position within the buffer (tellp) std::streampos output_pos() const { - return (buffer_type::span_tellp()); + return buffer_type::span_tellp(); + } + + //- The number of bytes outputted + std::streamsize count() const + { + return buffer_type::size_bytes(); } //- The put buffer capacity @@ -189,33 +195,6 @@ public: }; -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::OCharStreamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- An allocator for holding Foam::ocharstream -class OCharStreamAllocator -{ -protected: - - // Protected Data - - //- The stream - Foam::ocharstream stream_; - - - // Constructors - - //- Default construct - empty - OCharStreamAllocator() = default; -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class OCharStream Declaration \*---------------------------------------------------------------------------*/ @@ -223,10 +202,12 @@ protected: //- An OSstream with internal List storage class OCharStream : - public Detail::OCharStreamAllocator, + public Foam::Detail::StreamAllocator, public Foam::OSstream { - typedef Detail::OCharStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: @@ -277,8 +258,11 @@ public: //- The current output position within the buffer (tellp) std::streampos output_pos() const { return stream_.output_pos(); } - //- The current output size. Same as tellp(), output_pos() - label size() const { return label(stream_.output_pos()); } + //- The number of bytes outputted + std::streamsize count() const { return stream_.count(); } + + //- The current output size. Same as count(), output_pos(), tellp(). + label size() const { return label(stream_.count()); } //- The put buffer capacity std::streamsize capacity() const { return stream_.capacity(); } diff --git a/src/OpenFOAM/db/IOstreams/memory/OCountStream.H b/src/OpenFOAM/db/IOstreams/memory/OCountStream.H index 1618dd51da..c1c92fc36d 100644 --- a/src/OpenFOAM/db/IOstreams/memory/OCountStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/OCountStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,7 +35,6 @@ Description #define Foam_OScountStream_H #include "OSstream.H" -#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -126,7 +125,7 @@ class ocountstream // Member Functions - //- The number of bytes counted. + //- The number of bytes counted std::streamsize count() const noexcept { return size_; } //- Reset the count @@ -155,7 +154,7 @@ public: //- This hides both signatures of std::basic_ios::rdbuf() countbuf* rdbuf() { return &buf_; } - //- \return The number of bytes counted + //- The number of bytes counted std::streamsize count() const noexcept { return buf_.count(); } //- Reset the count @@ -173,33 +172,6 @@ public: }; -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::OCountStreamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- An allocator for holding Foam::ocountstream -class OCountStreamAllocator -{ -protected: - - // Protected Data - - //- The output stream - Foam::ocountstream stream_; - - - // Constructors - - //- Default construct - OCountStreamAllocator() = default; -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class OCountStream Declaration \*---------------------------------------------------------------------------*/ @@ -207,10 +179,12 @@ protected: //- An output stream for calculating byte counts class OCountStream : - public Detail::OCountStreamAllocator, - public OSstream + public Foam::Detail::StreamAllocator, + public Foam::OSstream { - typedef Detail::OCountStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: @@ -238,10 +212,10 @@ public: // Member Functions - //- \return The number of bytes counted + //- The number of bytes counted std::streamsize count() const noexcept { return stream_.count(); } - //- \return The number of bytes counted + //- The number of bytes counted std::streamsize size() const noexcept { return stream_.count(); } //- Reset the count diff --git a/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H b/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H index 1903c5a6b6..58cf0e0b39 100644 --- a/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/OSpanStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -83,7 +83,6 @@ See Also #define Foam_OSpanStream_H #include "memoryStreamBuffer.H" -#include "DynamicList.H" #include "OSstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -141,6 +140,12 @@ public: return buffer_type::span_tellp(); } + //- The number of bytes outputted + std::streamsize count() const + { + return buffer_type::size_bytes(); + } + //- The put buffer capacity std::streamsize capacity() const { @@ -199,49 +204,23 @@ public: //- Some information about the output buffer position/capacity void debug_info(Ostream& os) const { - os << "put=" - << output_pos() << '/' << capacity(); + os << "put=" << output_pos() << '/' << capacity(); } }; -namespace Detail -{ - -/*---------------------------------------------------------------------------*\ - Class Detail::OSpanStreamAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- An allocator for holding Foam::ospanstream -class OSpanStreamAllocator -{ -protected: - - // Protected Data - - //- The stream - Foam::ospanstream stream_; - - - // Constructors - - //- Default construct (empty) - OSpanStreamAllocator() = default; -}; - -} // End namespace Detail - - /*---------------------------------------------------------------------------*\ Class OSpanStream Declaration \*---------------------------------------------------------------------------*/ class OSpanStream : - public Detail::OSpanStreamAllocator, + public Foam::Detail::StreamAllocator, public Foam::OSstream { - typedef Detail::OSpanStreamAllocator allocator_type; + typedef + Foam::Detail::StreamAllocator + allocator_type; public: @@ -314,8 +293,11 @@ public: //- The current output position within the buffer (tellp) std::streampos output_pos() const { return stream_.output_pos(); } - //- The current output size. Same as tellp(), output_pos() - label size() const { return label(stream_.output_pos()); } + //- The number of bytes outputted + std::streamsize count() const { return stream_.count(); } + + //- The current output size. Same as count(), output_pos(), tellp(). + label size() const { return label(stream_.count()); } //- The put buffer capacity std::streamsize capacity() const { return stream_.capacity(); } diff --git a/src/OpenFOAM/primitives/strings/lists/SubStrings.H b/src/OpenFOAM/primitives/strings/lists/SubStrings.H index 8279d2d10d..4892d7976c 100644 --- a/src/OpenFOAM/primitives/strings/lists/SubStrings.H +++ b/src/OpenFOAM/primitives/strings/lists/SubStrings.H @@ -109,19 +109,14 @@ public: this->push_back(range); } - //- Const reference to the first element, - //- for consistency with other OpenFOAM containers - auto first() const -> decltype(this->front()) - { - return this->front(); - } - - //- Const reference to the last element, - //- for consistency with other OpenFOAM containers - auto last() const -> decltype(this->back()) - { - return this->back(); - } + // FUTURE? + // #if __cplusplus >= 201703L + // std::string_view view(size_t pos) const + // {} + // #else + // stdFoam::span view(size_t pos) const + // {} + // #endif }; diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C index 7115ca125c..8769fe76ab 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C @@ -63,14 +63,6 @@ Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::Detail::MeshedSurfaceIOAllocator::~MeshedSurfaceIOAllocator() -{ - clear(); -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::Detail::MeshedSurfaceIOAllocator::setInstance diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H index 7fd3b4a9b2..f07b0a2f0c 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,7 +39,7 @@ SourceFiles #define Foam_MeshedSurfaceIOAllocator_H #include "pointIOField.H" -#include "faceIOList.H" +#include "faceIOList.H" // faceIOList and faceCompactIOList // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -62,8 +62,9 @@ class MeshedSurfaceIOAllocator //- Faces faceCompactIOList faces_; +public: - // Private Member Functions + // Generated Methods //- No copy construct MeshedSurfaceIOAllocator(const MeshedSurfaceIOAllocator&) = delete; @@ -72,8 +73,6 @@ class MeshedSurfaceIOAllocator void operator=(const MeshedSurfaceIOAllocator&) = delete; -public: - // Constructors //- Read construct from IOobjects @@ -99,7 +98,7 @@ public: //- Destructor - virtual ~MeshedSurfaceIOAllocator(); + virtual ~MeshedSurfaceIOAllocator() = default; // Member Functions @@ -116,25 +115,25 @@ public: // Access //- Non-const access to the points - pointIOField& storedIOPoints() + pointIOField& storedIOPoints() noexcept { return points_; } //- Non-const access to the faces - faceCompactIOList& storedIOFaces() + faceCompactIOList& storedIOFaces() noexcept { return faces_; } //- Const access to the points - const pointIOField& storedIOPoints() const + const pointIOField& storedIOPoints() const noexcept { return points_; } //- Const access to the faces - const faceCompactIOList& storedIOFaces() const + const faceCompactIOList& storedIOFaces() const noexcept { return faces_; }