mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user