NamedEnum.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::NamedEnum
26 
27 Description
28  Initialise the NamedEnum HashTable from the static list of names.
29 
30 SourceFiles
31  NamedEnum.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef NamedEnum_H
36 #define NamedEnum_H
37 
38 #include "HashTable.H"
39 #include "stringList.H"
40 #include "wordList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class NamedEnum Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class Enum, unsigned int nEnum>
52 class NamedEnum
53 :
54  public HashTable<unsigned int>
55 {
56  // Private Member Functions
57 
58  //- Disallow default bitwise copy construction
59  NamedEnum(const NamedEnum&) = delete;
60 
61  //- Disallow default bitwise assignment
62  void operator=(const NamedEnum&) = delete;
63 
64 
65 public:
66 
67  // Static Data Members
68 
69  //- The set of names corresponding to the enumeration Enum
70  static const char* names[nEnum];
71 
72 
73  // Constructors
74 
75  //- Construct from names
76  NamedEnum();
77 
78 
79  // Member Functions
80 
81  //- Read a word from Istream and return the corresponding
82  // enumeration element
83  Enum read(Istream&) const;
84 
85  //- Write the name representation of the enumeration to an Ostream
86  void write(const Enum e, Ostream&) const;
87 
88  //- The set of names as a list of strings
89  static stringList strings();
90 
91  //- The set of names as a list of words
92  static wordList words();
93 
94 
95  // Member Operators
96 
97  //- Return the enumeration element corresponding to the given name
98  const Enum operator[](const char* name) const
99  {
100  return Enum(HashTable<unsigned int>::operator[](name));
101  }
102 
103  //- Return the enumeration element corresponding to the given name
104  const Enum operator[](const word& name) const
105  {
106  return Enum(HashTable<unsigned int>::operator[](name));
107  }
108 
109  //- Return the name of the given enumeration element
110  const char* operator[](const Enum e) const;
111 };
112 
113 
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115 
116 } // End namespace Foam
117 
118 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119 
120 #ifdef NoRepository
121  #include "NamedEnum.C"
122 #endif
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 #endif
127 
128 // ************************************************************************* //
static wordList words()
The set of names as a list of words.
Definition: NamedEnum.C:105
const Enum operator[](const char *name) const
Return the enumeration element corresponding to the given name.
Definition: NamedEnum.H:97
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void write(const Enum e, Ostream &) const
Write the name representation of the enumeration to an Ostream.
Definition: NamedEnum.C:79
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
static stringList strings()
The set of names as a list of strings.
Definition: NamedEnum.C:86
const char * names[]
Definition: EDC.C:32
A class for handling words, derived from string.
Definition: word.H:59
NamedEnum()
Construct from names.
Definition: NamedEnum.C:31
An STL-conforming hash table.
Definition: HashTable.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
Definition: NamedEnum.C:61
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
Namespace for OpenFOAM.