From b9e0ca1d1b4e2d9f818fab92320518040dc4423c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 30 Oct 2019 12:54:52 +0100 Subject: [PATCH] ENH: add Enum single-parameter operator() to resemble a unary function --- src/OpenFOAM/primitives/enums/Enum.H | 13 +++++++++---- src/OpenFOAM/primitives/enums/EnumI.H | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/primitives/enums/Enum.H b/src/OpenFOAM/primitives/enums/Enum.H index 8d28977ba0..b59ce442ea 100644 --- a/src/OpenFOAM/primitives/enums/Enum.H +++ b/src/OpenFOAM/primitives/enums/Enum.H @@ -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, diff --git a/src/OpenFOAM/primitives/enums/EnumI.H b/src/OpenFOAM/primitives/enums/EnumI.H index 35937fa613..be7308849b 100644 --- a/src/OpenFOAM/primitives/enums/EnumI.H +++ b/src/OpenFOAM/primitives/enums/EnumI.H @@ -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::operator[] } +template +inline const Foam::word& Foam::Enum::operator() +( + const EnumType e +) const +{ + return get(e); +} + + template inline EnumType Foam::Enum::operator() ( const word& enumName, - const EnumType defaultValue + const EnumType deflt ) const { const label idx = find(enumName); @@ -154,7 +164,7 @@ inline EnumType Foam::Enum::operator() return EnumType(vals_[idx]); } - return defaultValue; + return deflt; }