1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "NamedEnum.H"
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 template<class Enum, int nEnum>
31 Foam::NamedEnum<Enum, nEnum>::NamedEnum()
33 HashTable<int>(2*nEnum)
35 for (int enumI = 0; enumI < nEnum; ++enumI)
37 if (!names[enumI] || names[enumI][0] == '\0')
39 stringList goodNames(enumI);
41 for (int i = 0; i < enumI; ++i)
43 goodNames[i] = names[i];
46 FatalErrorIn("NamedEnum<Enum, nEnum>::NamedEnum()")
47 << "Illegal enumeration name at position " << enumI << endl
48 << "after entries " << goodNames << ".\n"
49 << "Possibly your NamedEnum<Enum, nEnum>::names array"
50 << " is not of size " << nEnum << endl
53 insert(names[enumI], enumI);
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
60 template<class Enum, int nEnum>
61 Enum Foam::NamedEnum<Enum, nEnum>::read(Istream& is) const
65 HashTable<int>::const_iterator iter = find(name);
67 if (iter == HashTable<int>::end())
71 "NamedEnum<Enum, nEnum>::read(Istream&) const", is
72 ) << name << " is not in enumeration: "
73 << sortedToc() << exit(FatalIOError);
80 template<class Enum, int nEnum>
81 void Foam::NamedEnum<Enum, nEnum>::write(const Enum e, Ostream& os) const
87 template<class Enum, int nEnum>
88 Foam::stringList Foam::NamedEnum<Enum, nEnum>::strings()
90 stringList lst(nEnum);
93 for (int enumI = 0; enumI < nEnum; ++enumI)
95 if (names[enumI] && names[enumI][0])
97 lst[nElem++] = names[enumI];
106 template<class Enum, int nEnum>
107 Foam::wordList Foam::NamedEnum<Enum, nEnum>::words()
112 for (int enumI = 0; enumI < nEnum; ++enumI)
114 if (names[enumI] && names[enumI][0])
116 lst[nElem++] = names[enumI];
125 // ************************************************************************* //