diff --git a/src/OpenFOAM/primitives/enums/Enum.C b/src/OpenFOAM/primitives/enums/Enum.C index 8c8eabca77b7bc82a576df5778be31e207a8493e..42821200d049c478ae9331a96e3f63eab04f2170 100644 --- a/src/OpenFOAM/primitives/enums/Enum.C +++ b/src/OpenFOAM/primitives/enums/Enum.C @@ -138,7 +138,7 @@ template<class EnumType> bool Foam::Enum<EnumType>::read ( Istream& is, - EnumType& e, + EnumType& val, const bool mandatory ) const { @@ -148,7 +148,7 @@ bool Foam::Enum<EnumType>::read if (idx >= 0) { - e = EnumType(vals_[idx]); + val = EnumType(vals_[idx]); return true; } @@ -266,17 +266,4 @@ bool Foam::Enum<EnumType>::readEntry } -template<class EnumType> -bool Foam::Enum<EnumType>::readIfPresent -( - const word& key, - const dictionary& dict, - EnumType& val -) const -{ - // Reading is non-mandatory - return readEntry(key, dict, val, false); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/enums/Enum.H b/src/OpenFOAM/primitives/enums/Enum.H index a9464b49b1185d5d6f3871b359ea3d2bcf055790..9294762140d46151810c7b250117fef8a4c0c6a4 100644 --- a/src/OpenFOAM/primitives/enums/Enum.H +++ b/src/OpenFOAM/primitives/enums/Enum.H @@ -50,7 +50,7 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations class dictionary; template<class EnumType> class Enum; @@ -85,8 +85,8 @@ public: // Constructors - //- Construct null (empty list) - Enum() = default; + //- Default construct, an empty list + Enum() noexcept = default; //- Construct from a values/names list. // Duplicate values are permitted (eg, for aliases). @@ -205,7 +205,7 @@ public: // Default search: non-recursive with patterns. // // \return true if the entry was found. - bool readIfPresent + inline bool readIfPresent ( const word& key, //!< Lookup key. Uses LITERAL (not REGEX) const dictionary& dict, //!< dictionary @@ -231,9 +231,10 @@ public: // A noop if the enumeration wasn't found. inline void write(const EnumType e, Ostream& os) const; - //- Write the names as a list to an Ostream. - // Default is without line-breaks. - inline Ostream& writeList(Ostream& os, const label shortLen=0) const; + //- Write enumeration names as a list without line-breaks + //- to an output stream. + template<class OS> + inline OS& writeList(OS& os, const label ununsed=0) const; // Member Operators diff --git a/src/OpenFOAM/primitives/enums/EnumI.H b/src/OpenFOAM/primitives/enums/EnumI.H index 9c2e1520c1f5493549f2d9bf126539d7db47aeff..33f8aaa20ed4f8382d902f39b7db268d7ac2f1a3 100644 --- a/src/OpenFOAM/primitives/enums/EnumI.H +++ b/src/OpenFOAM/primitives/enums/EnumI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -113,13 +113,15 @@ inline const Foam::word& Foam::Enum<EnumType>::get(const EnumType e) const template<class EnumType> -inline Foam::Ostream& Foam::Enum<EnumType>::writeList +inline bool Foam::Enum<EnumType>::readIfPresent ( - Ostream& os, - const label shortLen + const word& key, + const dictionary& dict, + EnumType& val ) const { - return keys_.writeList(os, shortLen); + // Reading is non-mandatory + return readEntry(key, dict, val, false); } @@ -135,6 +137,24 @@ inline void Foam::Enum<EnumType>::write(const EnumType e, Ostream& os) const } +template<class EnumType> +template<class OS> +inline OS& Foam::Enum<EnumType>::writeList(OS& os, const label) const +{ + unsigned i = 0; + + os << '('; + for (const word& k : keys_) + { + if (i++) os << ' '; + os << k; + } + os << ')'; + + return os; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class EnumType> @@ -194,7 +214,7 @@ inline Foam::Ostream& Foam::operator<< const Enum<EnumType>& list ) { - return list.names().writeList(os, 0); + return list.writeList(os); } @@ -205,19 +225,7 @@ inline std::ostream& Foam::operator<< const Enum<EnumType>& list ) { - os << '('; - - unsigned i = 0; - - for (const word& k : list.names()) - { - if (i++) os << ' '; - os << k; - } - - os << ')'; - - return os; + return list.writeList(os); }