diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 499bad8cb2..b6d3b227ec 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -208,12 +208,9 @@ Foam::Istream& Foam::ITstream::read(token& tok) { if (eof()) { - FatalIOErrorInFunction - ( - *this - ) << "attempt to read beyond EOF" + FatalIOErrorInFunction(*this) + << "attempt to read beyond EOF" << exit(FatalIOError); - setBad(); } else diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C index a46a82be52..5cf0a09c63 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C @@ -54,13 +54,11 @@ void Foam::dimensioned::initialize(Istream& is) if (dims != dimensions_) { - FatalIOErrorInFunction - ( - is - ) << "The dimensions " << dims - << " provided do not match the required dimensions " - << dimensions_ - << abort(FatalIOError); + FatalIOErrorInFunction(is) + << "The dimensions " << dims + << " provided do not match the required dimensions " + << dimensions_ + << abort(FatalIOError); } } diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.C b/src/OpenFOAM/primitives/Scalar/Scalar.C index c478f462bb..4e50312a83 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.C +++ b/src/OpenFOAM/primitives/Scalar/Scalar.C @@ -40,6 +40,7 @@ const Scalar pTraits::rootMax = ScalarROOTVGREAT; const char* const pTraits::componentNames[] = { "" }; + pTraits::pTraits(const Scalar& val) : p_(val) @@ -132,6 +133,9 @@ Istream& operator>>(Istream& is, Scalar& val) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get scalar value" + << exit(FatalIOError); is.setBad(); return is; } @@ -139,16 +143,18 @@ Istream& operator>>(Istream& is, Scalar& val) if (t.isNumber()) { val = t.number(); - is.check(FUNCTION_NAME); } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected Scalar, found " << t.info() + << "Wrong token type - expected scalar value, found " + << t.info() << exit(FatalIOError); + is.setBad(); + return is; } + is.check(FUNCTION_NAME); return is; } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.C b/src/OpenFOAM/primitives/bools/Switch/Switch.C index 71e9c1c818..fc2b4cc3d1 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.C +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.C @@ -161,6 +161,9 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& sw) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get bool" + << exit(FatalIOError); is.setBad(); return is; } @@ -171,26 +174,26 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& sw) } else if (t.isWord()) { - // Allow reading invalid value, but report immediately + // Permit invalid value, but catch immediately for better messages sw = Switch(t.wordToken(), true); if (!sw.valid()) { - is.setBad(); FatalIOErrorInFunction(is) - << "expected 'true/false', 'on/off' ... found " << t.wordToken() + << "Expected 'true/false', 'on/off' ... found " + << t.wordToken() << exit(FatalIOError); - + is.setBad(); return is; } } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected bool, found " << t + << "Wrong token type - expected bool, found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/direction/directionIO.C b/src/OpenFOAM/primitives/direction/directionIO.C index 135eaf89b1..fa234ccd3f 100644 --- a/src/OpenFOAM/primitives/direction/directionIO.C +++ b/src/OpenFOAM/primitives/direction/directionIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,6 +43,9 @@ Foam::Istream& Foam::operator>>(Istream& is, direction& d) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get direction" + << exit(FatalIOError); is.setBad(); return is; } @@ -53,11 +56,11 @@ Foam::Istream& Foam::operator>>(Istream& is, direction& d) } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected direction, found " << t.info() + << "Wrong token type - expected label (direction), found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/ints/int32/int32IO.C b/src/OpenFOAM/primitives/ints/int32/int32IO.C index 926421ff2b..b49a9cb8f8 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32IO.C +++ b/src/OpenFOAM/primitives/ints/int32/int32IO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -80,6 +80,9 @@ Foam::Istream& Foam::operator>>(Istream& is, int32_t& val) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get int32" + << exit(FatalIOError); is.setBad(); return is; } @@ -90,11 +93,11 @@ Foam::Istream& Foam::operator>>(Istream& is, int32_t& val) } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected int32_t, found " << t.info() + << "Wrong token type - expected label (int32), found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C index 6149c07b58..e23b406f51 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64IO.C +++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C @@ -80,6 +80,9 @@ Foam::Istream& Foam::operator>>(Istream& is, int64_t& val) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get int64" + << exit(FatalIOError); is.setBad(); return is; } @@ -90,11 +93,11 @@ Foam::Istream& Foam::operator>>(Istream& is, int64_t& val) } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected int64_t, found " << t.info() + << "Wrong token type - expected label (int64), found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C index 96fdc8c85b..a3bc90d5ea 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C +++ b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -79,6 +79,9 @@ Foam::Istream& Foam::operator>>(Istream& is, uint32_t& val) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get uint32" + << exit(FatalIOError); is.setBad(); return is; } @@ -89,11 +92,11 @@ Foam::Istream& Foam::operator>>(Istream& is, uint32_t& val) } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected uint32_t, found " << t.info() + << "Wrong token type - expected label (uint32), found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C index 7a1578a3c2..7eb9c30888 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C @@ -79,6 +79,9 @@ Foam::Istream& Foam::operator>>(Istream& is, uint64_t& val) if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get uint64" + << exit(FatalIOError); is.setBad(); return is; } @@ -89,11 +92,11 @@ Foam::Istream& Foam::operator>>(Istream& is, uint64_t& val) } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected uint64_t, found " << t.info() + << "Wrong token type - expected label (uint64), found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C index 42ab4f6936..79cb2a4547 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,31 +36,34 @@ Foam::fileName::fileName(Istream& is) } -Foam::Istream& Foam::operator>>(Istream& is, fileName& fn) +Foam::Istream& Foam::operator>>(Istream& is, fileName& val) { token t(is); if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get string" + << exit(FatalIOError); is.setBad(); return is; } if (t.isString()) { - fn = t.stringToken(); + val = t.stringToken(); } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected string, found " << t.info() + << "Wrong token type - expected string, found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } - fn.stripInvalid(); + val.stripInvalid(); is.check(FUNCTION_NAME); return is; diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.C b/src/OpenFOAM/primitives/strings/keyType/keyType.C index ca10362cbf..214dd1d95c 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.C +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,44 +58,46 @@ bool Foam::keyType::match(const std::string& text, bool literal) const // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // -Foam::Istream& Foam::operator>>(Istream& is, keyType& kw) +Foam::Istream& Foam::operator>>(Istream& is, keyType& val) { token t(is); if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get a word/regex" + << exit(FatalIOError); is.setBad(); return is; } if (t.isWord()) { - kw = t.wordToken(); + val = t.wordToken(); } else if (t.isString()) { - // Assign from string. Set as regular expression. - kw = t.stringToken(); - kw.isPattern_ = true; + // Assign from string, treat as regular expression + val = t.stringToken(); + val.isPattern_ = true; - // flag empty strings as an error - if (kw.empty()) + // Flag empty strings as an error + if (val.empty()) { - is.setBad(); FatalIOErrorInFunction(is) - << "empty word/expression " + << "Empty word/expression" << exit(FatalIOError); + is.setBad(); return is; } } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected word or string, found " + << "Wrong token type - expected word or string, found " << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/strings/string/stringIO.C b/src/OpenFOAM/primitives/strings/string/stringIO.C index 53c728b548..2c64538178 100644 --- a/src/OpenFOAM/primitives/strings/string/stringIO.C +++ b/src/OpenFOAM/primitives/strings/string/stringIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,27 +36,30 @@ Foam::string::string(Istream& is) // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // -Foam::Istream& Foam::operator>>(Istream& is, string& s) +Foam::Istream& Foam::operator>>(Istream& is, string& val) { token t(is); if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get string" + << exit(FatalIOError); is.setBad(); return is; } if (t.isString()) { - s = t.stringToken(); + val = t.stringToken(); } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected string, found " << t.info() + << "Wrong token type - expected string, found " + << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/strings/word/wordIO.C b/src/OpenFOAM/primitives/strings/word/wordIO.C index e2a172b98a..b9d0fd056d 100644 --- a/src/OpenFOAM/primitives/strings/word/wordIO.C +++ b/src/OpenFOAM/primitives/strings/word/wordIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,46 +36,47 @@ Foam::word::word(Istream& is) } -Foam::Istream& Foam::operator>>(Istream& is, word& w) +Foam::Istream& Foam::operator>>(Istream& is, word& val) { token t(is); if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get word" + << exit(FatalIOError); is.setBad(); return is; } if (t.isWord()) { - w = t.wordToken(); + val = t.wordToken(); } else if (t.isString()) { // Try a bit harder and convert string to word - w = t.stringToken(); - string::stripInvalid(w); + val = t.stringToken(); + string::stripInvalid(val); // Flag empty strings and bad chars as an error - if (w.empty() || w.size() != t.stringToken().size()) + if (val.empty() || val.size() != t.stringToken().size()) { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected word," - " found non-word characters " + << "Empty word or non-word characters " << t.info() << exit(FatalIOError); + is.setBad(); return is; } } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected word, found " + << "Wrong token type - expected word, found " << t.info() << exit(FatalIOError); - + is.setBad(); return is; } diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C index cbee07ee73..4ce9a2800d 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,43 +45,45 @@ Foam::wordRe::wordRe(Istream& is) // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // -Foam::Istream& Foam::operator>>(Istream& is, wordRe& w) +Foam::Istream& Foam::operator>>(Istream& is, wordRe& val) { token t(is); if (!t.good()) { + FatalIOErrorInFunction(is) + << "Bad token - could not get wordRe" + << exit(FatalIOError); is.setBad(); return is; } if (t.isWord()) { - w = t.wordToken(); + val = t.wordToken(); } else if (t.isString()) { - // Auto-tests for regular expression - w = t.stringToken(); + // Auto-detects regex + val = t.stringToken(); - // flag empty strings as an error - if (w.empty()) + // Flag empty strings as an error + if (val.empty()) { - is.setBad(); FatalIOErrorInFunction(is) - << "empty word/expression " + << "Empty word/expression" << exit(FatalIOError); + is.setBad(); return is; } } else { - is.setBad(); FatalIOErrorInFunction(is) - << "wrong token type - expected word or string, found " + << "Wrong token type - expected word or string, found " << t.info() << exit(FatalIOError); - + is.setBad(); return is; }