1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Initialise the NamedEnum HashTable from the static list of names.
34 \*---------------------------------------------------------------------------*/
39 #include "HashTable.H"
40 #include "StaticAssert.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 /*---------------------------------------------------------------------------*\
48 Class NamedEnum Declaration
49 \*---------------------------------------------------------------------------*/
51 template<class Enum, int nEnum>
57 //- nEnum must be positive (non-zero)
58 StaticAssert(nEnum > 0);
62 // Private Member Functions
64 //- Disallow default bitwise copy construct
65 NamedEnum(const NamedEnum&);
67 //- Disallow default bitwise assignment
68 void operator=(const NamedEnum&);
73 // Static data members
75 //- The set of names corresponding to the enumeration Enum
76 static const char* names[nEnum];
81 //- Construct from names
87 //- Read a word from Istream and return the corresponding
88 // enumeration element
89 Enum read(Istream&) const;
91 //- Write the name representation of the enumeration to an Ostream
92 void write(const Enum e, Ostream&) const;
97 //- Return the enumeration element corresponding to the given name
98 const Enum operator[](const char* name) const
100 return Enum(HashTable<int>::operator[](name));
103 //- Return the enumeration element corresponding to the given name
104 const Enum operator[](const word& name) const
106 return Enum(HashTable<int>::operator[](name));
109 //- Return the name of the given enumeration element
110 const char* operator[](const Enum e) const
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119 } // End namespace Foam
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 # include "NamedEnum.C"
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 // ************************************************************************* //