Skip to content
Snippets Groups Projects
Commit f7839acd authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: output Enum name list without leading number

- not usually of any interest.
  Unifies code for Ostream and std::ostream operators
parent f1d9fea6
No related merge requests found
......@@ -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);
}
// ************************************************************************* //
......@@ -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
......
......@@ -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);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment