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

This commit is contained in:
Mark Olesen
2019-10-30 12:54:52 +01:00
committed by Andrew Heather
parent c5ed28d0e3
commit b9e0ca1d1b
2 changed files with 22 additions and 7 deletions

View File

@ -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,

View File

@ -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;
}