mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add failsafe version of Enum::get()
This commit is contained in:
committed by
Andrew Heather
parent
27c58dde4c
commit
e5b3af9c05
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -77,6 +77,24 @@ EnumType Foam::Enum<EnumType>::get(const word& enumName) const
|
||||
}
|
||||
|
||||
|
||||
template<class EnumType>
|
||||
EnumType Foam::Enum<EnumType>::get
|
||||
(
|
||||
const word& enumName,
|
||||
const EnumType defaultValue
|
||||
) const
|
||||
{
|
||||
const label idx = find(enumName);
|
||||
|
||||
if (idx < 0)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return EnumType(vals_[idx]);
|
||||
}
|
||||
|
||||
|
||||
template<class EnumType>
|
||||
EnumType Foam::Enum<EnumType>::read(Istream& is) const
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -130,6 +130,10 @@ public:
|
||||
// FatalError if not found.
|
||||
EnumType get(const word& enumName) const;
|
||||
|
||||
//- The enumeration corresponding to the given name.
|
||||
// \return The enumeration or default if not found.
|
||||
EnumType get(const word& enumName, const EnumType defaultValue) const;
|
||||
|
||||
//- The name corresponding to the given enumeration.
|
||||
// Return an empty word if not found.
|
||||
inline const word& get(const EnumType e) const;
|
||||
|
||||
Reference in New Issue
Block a user