mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add ITstream::toString() method
- creates a std::string with space-delimited tokens, which can be sent to another application or even re-parsed into tokens
This commit is contained in:
committed by
Andrew Heather
parent
771410e546
commit
ba69505225
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user