diff --git a/src/OpenFOAM/primitives/enums/Enum.C b/src/OpenFOAM/primitives/enums/Enum.C index f74a393a562c7cab7cd5adfff0f56effcbb3c235..1e269ff4ede1989814249bfec1da5f2d03cdae96 100644 --- a/src/OpenFOAM/primitives/enums/Enum.C +++ b/src/OpenFOAM/primitives/enums/Enum.C @@ -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 { diff --git a/src/OpenFOAM/primitives/enums/Enum.H b/src/OpenFOAM/primitives/enums/Enum.H index 25b73632e69c9e1dce5b101520e79bcb13d3f34e..b5ef2a362444626456533d27cf0aca02878b6b1e 100644 --- a/src/OpenFOAM/primitives/enums/Enum.H +++ b/src/OpenFOAM/primitives/enums/Enum.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 @@ -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;