diff --git a/src/OpenFOAM/containers/NamedEnum/NamedEnum.C b/src/OpenFOAM/containers/NamedEnum/NamedEnum.C index 05733eadf2..f96bea14fe 100644 --- a/src/OpenFOAM/containers/NamedEnum/NamedEnum.C +++ b/src/OpenFOAM/containers/NamedEnum/NamedEnum.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -120,4 +120,25 @@ Foam::wordList Foam::NamedEnum::words() } +template +const char* Foam::NamedEnum::operator[](const Enum e) const +{ + unsigned int ue = unsigned(e); + + if (ue < nEnum) + { + return names[ue]; + } + else + { + FatalErrorInFunction + << "names array index " << ue << " out of range 0-" + << nEnum - 1 + << exit(FatalError); + + return names[0]; + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/containers/NamedEnum/NamedEnum.H b/src/OpenFOAM/containers/NamedEnum/NamedEnum.H index e5ed68ddbf..7d9fae597b 100644 --- a/src/OpenFOAM/containers/NamedEnum/NamedEnum.H +++ b/src/OpenFOAM/containers/NamedEnum/NamedEnum.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,7 +38,6 @@ SourceFiles #include "HashTable.H" #include "stringList.H" #include "wordList.H" -#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -108,10 +107,7 @@ public: } //- Return the name of the given enumeration element - const char* operator[](const Enum e) const - { - return names[unsigned(e)]; - } + const char* operator[](const Enum e) const; };