Skip to content
Snippets Groups Projects
Commit e5b3af9c authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: add failsafe version of Enum::get()

parent 27c58dde
Branches
Tags
No related merge requests found
......@@ -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;
......
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