mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: robuster handling of unknown stream/float formats
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -70,7 +70,7 @@ Foam::IOstreamOption::floatFormatEnum
|
||||
|
||||
if (!fmtName.empty())
|
||||
{
|
||||
const auto iter = floatFormatNames.cfind(fmtName);
|
||||
auto iter = floatFormatNames.cfind(fmtName);
|
||||
|
||||
if (iter.good())
|
||||
{
|
||||
@ -79,10 +79,19 @@ Foam::IOstreamOption::floatFormatEnum
|
||||
|
||||
// Fall-through to warning
|
||||
|
||||
WarningInFunction
|
||||
<< "Unknown float format specifier '" << fmtName
|
||||
<< "' using '" << floatFormatNames[deflt]
|
||||
<< "' from " << floatFormatNames << nl;
|
||||
auto& err = WarningInFunction
|
||||
<< "Unknown float format '" << fmtName << "' using ";
|
||||
|
||||
iter = floatFormatNames.cfind(deflt);
|
||||
if (iter.good())
|
||||
{
|
||||
err << '\'' << iter.key() << '\'';
|
||||
}
|
||||
else
|
||||
{
|
||||
err << "value=" << int(deflt);
|
||||
}
|
||||
err << " from " << floatFormatNames << nl;
|
||||
}
|
||||
|
||||
return deflt;
|
||||
@ -112,7 +121,7 @@ Foam::IOstreamOption::formatEnum
|
||||
|
||||
if (!fmtName.empty())
|
||||
{
|
||||
const auto iter = formatNames.cfind(fmtName);
|
||||
auto iter = formatNames.cfind(fmtName);
|
||||
|
||||
if (iter.good())
|
||||
{
|
||||
@ -121,10 +130,19 @@ Foam::IOstreamOption::formatEnum
|
||||
|
||||
// Fall-through to warning
|
||||
|
||||
WarningInFunction
|
||||
<< "Unknown stream format specifier '" << fmtName
|
||||
<< "' using '" << formatNames[deflt]
|
||||
<< "' from " << formatNames << nl;
|
||||
auto& err = WarningInFunction
|
||||
<< "Unknown stream format '" << fmtName << "' using ";
|
||||
|
||||
iter = formatNames.cfind(deflt);
|
||||
if (iter.good())
|
||||
{
|
||||
err << '\'' << iter.key() << '\'';
|
||||
}
|
||||
else
|
||||
{
|
||||
err << "value=" << int(deflt);
|
||||
}
|
||||
err << " from " << formatNames << nl;
|
||||
}
|
||||
|
||||
return deflt;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -298,11 +298,16 @@ public:
|
||||
const_iterator begin() const noexcept { return cbegin(); }
|
||||
const_iterator end() const noexcept { return cend(); }
|
||||
|
||||
//- Find the enumeration by name.
|
||||
//- Find key/value pair by enumeration name.
|
||||
// Equal to cend() if not found, or test if good()
|
||||
inline const_iterator cfind(const word& key) const;
|
||||
const_iterator find(const word& key) const { return cfind(key); }
|
||||
|
||||
//- Find key/value pair by enumeration value.
|
||||
// Equal to cend() if not found, or test if good()
|
||||
inline const_iterator cfind(const EnumType e) const;
|
||||
const_iterator find(const EnumType e) const { return cfind(e); }
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -252,6 +252,20 @@ Foam::Enum<EnumType>::cfind(const word& key) const
|
||||
}
|
||||
|
||||
|
||||
template<class EnumType>
|
||||
inline typename Foam::Enum<EnumType>::const_iterator
|
||||
Foam::Enum<EnumType>::cfind(const EnumType e) const
|
||||
{
|
||||
const label idx = vals_.find(int(e));
|
||||
|
||||
return typename Enum<EnumType>::const_iterator
|
||||
(
|
||||
this,
|
||||
(idx >= 0 ? idx : this->size())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class EnumType>
|
||||
|
||||
Reference in New Issue
Block a user