Commit 857ee7ff authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add strings() and words() method to NamedEnum

- for situations where a list of strings/words is more useful than a
  raw array of C-strings
parent 7cb9c39b
......@@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "NamedEnum.H"
#include "stringList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -85,4 +84,42 @@ void Foam::NamedEnum<Enum, nEnum>::write(const Enum e, Ostream& os) const
}
template<class Enum, int nEnum>
Foam::stringList Foam::NamedEnum<Enum, nEnum>::strings()
{
stringList lst(nEnum);
label nElem = 0;
for (int enumI = 0; enumI < nEnum; ++enumI)
{
if (names[enumI] && names[enumI][0])
{
lst[nElem++] = names[enumI];
}
}
lst.setSize(nElem);
return lst;
}
template<class Enum, int nEnum>
Foam::wordList Foam::NamedEnum<Enum, nEnum>::words()
{
wordList lst(nEnum);
label nElem = 0;
for (int enumI = 0; enumI < nEnum; ++enumI)
{
if (names[enumI] && names[enumI][0])
{
lst[nElem++] = names[enumI];
}
}
lst.setSize(nElem);
return lst;
}
// ************************************************************************* //
......@@ -37,6 +37,8 @@ SourceFiles
#include "HashTable.H"
#include "StaticAssert.H"
#include "stringList.H"
#include "wordList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -87,6 +89,12 @@ public:
//- Write the name representation of the enumeration to an Ostream
void write(const Enum e, Ostream&) const;
//- The set of names as a list of strings
static stringList strings();
//- The set of names as a list of words
static wordList words();
// Member Operators
......
Markdown is supported
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