diff --git a/applications/test/codeStream/Test-codeStream.C b/applications/test/codeStream/Test-codeStream.C index e6b98160f5..f6dc1ecdb5 100644 --- a/applications/test/codeStream/Test-codeStream.C +++ b/applications/test/codeStream/Test-codeStream.C @@ -67,6 +67,14 @@ int main(int argc, char *argv[]) dictionary dict(is); Info<< dict << endl; + for (const entry& e : dict) + { + if (e.isStream()) + { + Info<< e.keyword() << " :: " + << e.stream().toString() << nl; + } + } } } diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 1c908e58b2..30c10b37f7 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -27,6 +27,7 @@ License #include "error.H" #include "ITstream.H" +#include "StringStream.H" #include "UIListStream.H" // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -187,6 +188,28 @@ void Foam::ITstream::print(Ostream& os) const } +std::string Foam::ITstream::toString() const +{ + OStringStream buf; + + const tokenList& tokens = *this; + + label len = tokens.size(); + + for (const token& tok : tokens) + { + buf << tok; + + if (--len) + { + buf << ' '; + } + } + + return buf.str(); +} + + Foam::Istream& Foam::ITstream::read(token& tok) { // Return the put back token if it exists diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index 02df5df7e6..e5d2c484a0 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -192,7 +192,7 @@ public: ); - // Member functions + // Member Functions // Inquiry @@ -233,7 +233,7 @@ public: } - // Read functions + // Read Functions //- Return next token from stream virtual Istream& read(token& tok); @@ -289,10 +289,14 @@ public: } - // Print + // Output //- Print description of stream to Ostream void print(Ostream& os) const; + + //- Concatenate tokens into a space-separated std::string. + //- The resulting string may contain quote characters. + std::string toString() const; };