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/>.
28 Initialise the NamedEnum HashTable from the static list of names.
33 \*---------------------------------------------------------------------------*/
38 #include "HashTable.H"
39 #include "StaticAssert.H"
40 #include "stringList.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 /*---------------------------------------------------------------------------*\
49 Class NamedEnum Declaration
50 \*---------------------------------------------------------------------------*/
52 template<class Enum, int nEnum>
57 //- nEnum must be positive (non-zero)
58 StaticAssert(nEnum > 0);
60 // Private Member Functions
62 //- Disallow default bitwise copy construct
63 NamedEnum(const NamedEnum&);
65 //- Disallow default bitwise assignment
66 void operator=(const NamedEnum&);
71 // Static data members
73 //- The set of names corresponding to the enumeration Enum
74 static const char* names[nEnum];
79 //- Construct from names
85 //- Read a word from Istream and return the corresponding
86 // enumeration element
87 Enum read(Istream&) const;
89 //- Write the name representation of the enumeration to an Ostream
90 void write(const Enum e, Ostream&) const;
92 //- The set of names as a list of strings
93 static stringList strings();
95 //- The set of names as a list of words
96 static wordList words();
101 //- Return the enumeration element corresponding to the given name
102 const Enum operator[](const char* name) const
104 return Enum(HashTable<int>::operator[](name));
107 //- Return the enumeration element corresponding to the given name
108 const Enum operator[](const word& name) const
110 return Enum(HashTable<int>::operator[](name));
113 //- Return the name of the given enumeration element
114 const char* operator[](const Enum e) const
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 } // End namespace Foam
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 # include "NamedEnum.C"
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 // ************************************************************************* //