FIX: getLine() line counting (adjustment to 459aaad0f9
)
ENH: return ITstream::emptyStream() in a 'bad' state - to indicate that it is invalid for reading
This commit is contained in:
parent
a03077e151
commit
3524a6f4df
@ -1,3 +1,3 @@
|
||||
Test-IFstream.C
|
||||
Test-IFstream.cxx
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-IFstream
|
||||
|
@ -66,7 +66,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Test that buffer resizing works as expected
|
||||
|
||||
Info<< "buf: " << buf.size() << '/' << buf.capacity() << nl;
|
||||
Info<< "buf: " << buf.size() << '/' << buf.capacity()
|
||||
<< nl << nl;
|
||||
|
||||
bool skipDoc = true;
|
||||
|
||||
@ -89,14 +90,13 @@ int main(int argc, char *argv[])
|
||||
<< nl;
|
||||
|
||||
auto n = is.getLine(nullptr, '}');
|
||||
Info<< is.lineNumber() << ": [" << label(n) << "]" << nl;
|
||||
Info<< is.lineNumber() << ": [" << label(n) << ']' << nl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto n = is.getLine(nullptr);
|
||||
|
||||
Info<< is.lineNumber() << ": [" << label(n) << "]" << nl;
|
||||
auto n = is.getLine(nullptr); // default: '\n'
|
||||
Info<< is.lineNumber() << ": [" << label(n) << ']' << nl;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
Test-ITstream.C
|
||||
Test-ITstream.cxx
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-ITstream
|
||||
|
@ -24,6 +24,8 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Basic test for ITstream, which is the input token stream used by
|
||||
primitiveEntry (dictionary).
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -473,6 +475,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
reverse(listInput);
|
||||
doTest("List<char>", listInput, true);
|
||||
|
||||
|
||||
{
|
||||
auto& empty = ITstream::emptyStream();
|
||||
Info<< "The empty stream:" << nl
|
||||
<< " name: " << empty.name()
|
||||
<< " good:" << empty.good()
|
||||
<< " content:" << empty << nl;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.found("rewrite"))
|
@ -1,3 +1,3 @@
|
||||
Test-OFstream.C
|
||||
Test-OFstream.cxx
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-OFstream
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -76,10 +76,10 @@ inline int Foam::ISstream::peek()
|
||||
inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
|
||||
{
|
||||
std::getline(is_, str, delim);
|
||||
std::streamsize count = is_.gcount();
|
||||
syncState();
|
||||
|
||||
if (delim == '\n' && count > 0)
|
||||
// Unlike with ignore(), cannot use gcount() to test success
|
||||
if (delim == '\n')
|
||||
{
|
||||
++lineNumber_;
|
||||
}
|
||||
|
@ -84,6 +84,9 @@ Foam::ITstream& Foam::ITstream::emptyStream()
|
||||
emptyStreamPtr_.reset(new ITstream(Foam::zero{}, "empty-stream"));
|
||||
}
|
||||
|
||||
// Set stream as bad to indicate that this is an invald stream
|
||||
emptyStreamPtr_->setBad();
|
||||
|
||||
return *emptyStreamPtr_;
|
||||
}
|
||||
|
||||
@ -296,14 +299,14 @@ void Foam::ITstream::print(Ostream& os) const
|
||||
{
|
||||
os << "ITstream : " << name_.c_str() << ", line ";
|
||||
|
||||
const tokenList& toks = *this;
|
||||
|
||||
if (toks.empty())
|
||||
if (tokenList::empty())
|
||||
{
|
||||
os << lineNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
const tokenList& toks = *this;
|
||||
|
||||
os << toks.front().lineNumber();
|
||||
|
||||
if (toks.front().lineNumber() < toks.back().lineNumber())
|
||||
|
@ -190,9 +190,15 @@ public:
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Return readable reference to an empty ITstream.
|
||||
//- For functions needing to return an ITstream reference
|
||||
//- that don't have anything valid.
|
||||
//- Return reference to an empty ITstream, for functions needing to
|
||||
//- return an ITstream reference but which don't have anything valid
|
||||
//- of their own. <b>The stream shall be considered \em read-only.</b>
|
||||
//
|
||||
// The returned stream has no tokens and has a 'bad' state,
|
||||
// to indicate that it is invalid for reading.
|
||||
//
|
||||
// \caution the caller can still modify the its contents,
|
||||
// but they should not do that!
|
||||
static ITstream& emptyStream();
|
||||
|
||||
//- Create token list by parsing the input character sequence
|
||||
|
Loading…
Reference in New Issue
Block a user