mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make checkITstream methods public (dictionary, entry)
- permits use of these checks for routines wishing to handle their own logic.
This commit is contained in:
@ -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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * 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
|
bool Foam::dictionary::found
|
||||||
(
|
(
|
||||||
const word& keyword,
|
const word& keyword,
|
||||||
|
|||||||
@ -357,12 +357,6 @@ private:
|
|||||||
) const;
|
) 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:
|
public:
|
||||||
|
|
||||||
// Declare name of the class and its debug switch
|
// Declare name of the class and its debug switch
|
||||||
@ -799,6 +793,11 @@ public:
|
|||||||
|
|
||||||
// Read
|
// 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
|
//- Read dictionary from Istream
|
||||||
bool read(Istream& is);
|
bool read(Istream& is);
|
||||||
|
|
||||||
|
|||||||
@ -93,7 +93,7 @@ bool Foam::dictionary::readCompat
|
|||||||
ITstream& is = finder.ptr()->stream();
|
ITstream& is = finder.ptr()->stream();
|
||||||
is >> val;
|
is >> val;
|
||||||
|
|
||||||
checkITstream(keyword, is);
|
checkITstream(is, keyword);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ T Foam::dictionary::lookupOrDefault
|
|||||||
ITstream& is = finder.ptr()->stream();
|
ITstream& is = finder.ptr()->stream();
|
||||||
is >> val;
|
is >> val;
|
||||||
|
|
||||||
checkITstream(keyword, is);
|
checkITstream(is, keyword);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ T Foam::dictionary::lookupOrAddDefault
|
|||||||
ITstream& is = finder.ptr()->stream();
|
ITstream& is = finder.ptr()->stream();
|
||||||
is >> val;
|
is >> val;
|
||||||
|
|
||||||
checkITstream(keyword, is);
|
checkITstream(is, keyword);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ bool Foam::dictionary::readEntry
|
|||||||
ITstream& is = finder.ptr()->stream();
|
ITstream& is = finder.ptr()->stream();
|
||||||
is >> val;
|
is >> val;
|
||||||
|
|
||||||
checkITstream(keyword, is);
|
checkITstream(is, keyword);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ T Foam::dictionary::lookupOrDefaultCompat
|
|||||||
ITstream& is = finder.ptr()->stream();
|
ITstream& is = finder.ptr()->stream();
|
||||||
is >> val;
|
is >> val;
|
||||||
|
|
||||||
checkITstream(keyword, is);
|
checkITstream(is, keyword);
|
||||||
|
|
||||||
return val;
|
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
|
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 * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::entry::operator=(const entry& e)
|
void Foam::entry::operator=(const entry& e)
|
||||||
|
|||||||
@ -107,11 +107,6 @@ private:
|
|||||||
// \return True if it is a valid keyType.
|
// \return True if it is a valid keyType.
|
||||||
static bool getKeyword(keyType& keyword, Istream& is);
|
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:
|
public:
|
||||||
|
|
||||||
@ -245,9 +240,12 @@ public:
|
|||||||
virtual dictionary& dict() = 0;
|
virtual dictionary& dict() = 0;
|
||||||
|
|
||||||
|
|
||||||
//- Write
|
// Read
|
||||||
virtual void write(Ostream& os) const = 0;
|
|
||||||
|
|
||||||
|
//- 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,
|
//- Get a T from the stream,
|
||||||
//- FatalIOError if the number of tokens is incorrect.
|
//- FatalIOError if the number of tokens is incorrect.
|
||||||
@ -272,6 +270,11 @@ public:
|
|||||||
checkITstream(is);
|
checkITstream(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write
|
||||||
|
|
||||||
|
//- Write
|
||||||
|
virtual void write(Ostream& os) const = 0;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user