Commit 9b7ec718 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: make checkITstream methods public (dictionary, entry)

- permits use of these checks for routines wishing to handle their own
  logic.
parent a7a346b2
......@@ -46,89 +46,6 @@ bool Foam::dictionary::writeOptionalEntries
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::dictionary::checkITstream
(
const word& keyword,
const ITstream& is
) const
{
if (is.nRemainingTokens())
{
const label remaining = is.nRemainingTokens();
// Similar to SafeFatalIOError
if (JobInfo::constructed)
{
OSstream& err =
FatalIOError
(
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
is.lineNumber() // ioStartLineNumber
);
err << "'" << keyword << "' has "
<< remaining << " excess tokens in stream" << nl << nl
<< " ";
is.writeList(err, 0);
err << exit(FatalIOError);
}
else
{
std::cerr
<< nl
<< "--> FOAM FATAL IO ERROR:" << nl;
std::cerr
<< "'" << keyword << "' has "
<< remaining << " excess tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
}
}
else if (!is.size())
{
// Similar to SafeFatalIOError
if (JobInfo::constructed)
{
FatalIOError
(
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
is.lineNumber() // ioStartLineNumber
)
<< "'" << keyword << "' had no tokens in stream" << nl << nl
<< exit(FatalIOError);
}
else
{
std::cerr
<< nl
<< "--> FOAM FATAL IO ERROR:" << nl
<< "'" << keyword << "' had no tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -308,6 +225,88 @@ Foam::tokenList Foam::dictionary::tokens() const
}
void Foam::dictionary::checkITstream
(
const ITstream& is,
const word& keyword
) const
{
if (is.nRemainingTokens())
{
const label remaining = is.nRemainingTokens();
// Similar to SafeFatalIOError
if (JobInfo::constructed)
{
OSstream& err =
FatalIOError
(
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
is.lineNumber() // ioStartLineNumber
);
err << "'" << keyword << "' has "
<< remaining << " excess tokens in stream" << nl << nl
<< " ";
is.writeList(err, 0);
err << exit(FatalIOError);
}
else
{
std::cerr
<< nl
<< "--> FOAM FATAL IO ERROR:" << nl;
std::cerr
<< "'" << keyword << "' has "
<< remaining << " excess tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
}
}
else if (!is.size())
{
// Similar to SafeFatalIOError
if (JobInfo::constructed)
{
FatalIOError
(
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
is.lineNumber() // ioStartLineNumber
)
<< "'" << keyword << "' had no tokens in stream" << nl << nl
<< exit(FatalIOError);
}
else
{
std::cerr
<< nl
<< "--> FOAM FATAL IO ERROR:" << nl
<< "'" << keyword << "' had no tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
::exit(1);
}
}
}
bool Foam::dictionary::found
(
const word& keyword,
......
......@@ -357,12 +357,6 @@ private:
) const;
//- Check after reading if the input token stream has unconsumed
//- tokens remaining or if there were no tokens in the first place.
// Emits FatalIOError
void checkITstream(const word& keyword, const ITstream& is) const;
public:
// Declare name of the class and its debug switch
......@@ -799,6 +793,11 @@ public:
// Read
//- Check after reading if the input token stream has unconsumed
//- tokens remaining or if there were no tokens in the first place.
// Emits FatalIOError
void checkITstream(const ITstream& is, const word& keyword) const;
//- Read dictionary from Istream
bool read(Istream& is);
......
......@@ -93,7 +93,7 @@ bool Foam::dictionary::readCompat
ITstream& is = finder.ptr()->stream();
is >> val;
checkITstream(keyword, is);
checkITstream(is, keyword);
return true;
}
......@@ -126,7 +126,7 @@ T Foam::dictionary::lookupOrDefault
ITstream& is = finder.ptr()->stream();
is >> val;
checkITstream(keyword, is);
checkITstream(is, keyword);
return val;
}
......@@ -159,7 +159,7 @@ T Foam::dictionary::lookupOrAddDefault
ITstream& is = finder.ptr()->stream();
is >> val;
checkITstream(keyword, is);
checkITstream(is, keyword);
return val;
}
......@@ -192,7 +192,7 @@ bool Foam::dictionary::readEntry
ITstream& is = finder.ptr()->stream();
is >> val;
checkITstream(keyword, is);
checkITstream(is, keyword);
return true;
}
......@@ -239,7 +239,7 @@ T Foam::dictionary::lookupOrDefaultCompat
ITstream& is = finder.ptr()->stream();
is >> val;
checkITstream(keyword, is);
checkITstream(is, keyword);
return val;
}
......
......@@ -47,7 +47,29 @@ void Foam::entry::resetInputMode()
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::entry::entry(const keyType& keyword)
:
IDLList<entry>::link(),
keyword_(keyword)
{}
Foam::entry::entry(const entry& e)
:
IDLList<entry>::link(),
keyword_(e.keyword_)
{}
Foam::autoPtr<Foam::entry> Foam::entry::clone() const
{
return clone(dictionary::null);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::entry::checkITstream(const ITstream& is) const
{
......@@ -129,28 +151,6 @@ void Foam::entry::checkITstream(const ITstream& is) const
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::entry::entry(const keyType& keyword)
:
IDLList<entry>::link(),
keyword_(keyword)
{}
Foam::entry::entry(const entry& e)
:
IDLList<entry>::link(),
keyword_(e.keyword_)
{}
Foam::autoPtr<Foam::entry> Foam::entry::clone() const
{
return clone(dictionary::null);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::entry::operator=(const entry& e)
......
......@@ -107,11 +107,6 @@ private:
// \return True if it is a valid keyType.
static bool getKeyword(keyType& keyword, Istream& is);
//- Check after reading if the input token stream has unconsumed
//- tokens remaining or if there were no tokens in the first place.
// Emits FatalIOError
void checkITstream(const ITstream& is) const;
public:
......@@ -245,9 +240,12 @@ public:
virtual dictionary& dict() = 0;
//- Write
virtual void write(Ostream& os) const = 0;
// Read
//- Check after reading if the input token stream has unconsumed
//- tokens remaining or if there were no tokens in the first place.
// Emits FatalIOError
void checkITstream(const ITstream& is) const;
//- Get a T from the stream,
//- FatalIOError if the number of tokens is incorrect.
......@@ -272,6 +270,11 @@ public:
checkITstream(is);
}
// Write
//- Write
virtual void write(Ostream& os) const = 0;
// Member Operators
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment