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

ENH: add Enum single-parameter operator() to resemble a unary function

parent c5ed28d0
No related merge requests found
......@@ -211,13 +211,18 @@ public:
// Identical to single parameter get()
inline EnumType operator[](const word& enumName) const;
//- Return the first name corresponding to the given enumeration.
// Returns an empty word on failure.
//- Return the first name corresponding to the given enumeration,
//- or an empty word on failure.
// Identical to single parameter get()
inline const word& operator[](const EnumType e) const;
//- Return the enumeration corresponding to the given name or
//- deflt if the name is not found.
//- Return the first name corresponding to the given enumeration,
//- or an empty word on failure.
// Identical to single parameter get()
inline const word& operator()(const EnumType e) const;
//- Return the enumeration corresponding to the given name,
//- or deflt if the name is not found.
inline EnumType operator()
(
const word& enumName,
......
......@@ -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
......@@ -140,11 +140,21 @@ inline const Foam::word& Foam::Enum<EnumType>::operator[]
}
template<class EnumType>
inline const Foam::word& Foam::Enum<EnumType>::operator()
(
const EnumType e
) const
{
return get(e);
}
template<class EnumType>
inline EnumType Foam::Enum<EnumType>::operator()
(
const word& enumName,
const EnumType defaultValue
const EnumType deflt
) const
{
const label idx = find(enumName);
......@@ -154,7 +164,7 @@ inline EnumType Foam::Enum<EnumType>::operator()
return EnumType(vals_[idx]);
}
return defaultValue;
return deflt;
}
......
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