![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 NamedEnum 00027 00028 Description 00029 00030 SourceFiles 00031 NamedEnum.C 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef NamedEnum_H 00036 #define NamedEnum_H 00037 00038 #include "HashTable.H" 00039 00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00041 00042 namespace Foam 00043 { 00044 00045 /*---------------------------------------------------------------------------*\ 00046 Class NamedEnum Declaration 00047 \*---------------------------------------------------------------------------*/ 00048 00049 template<class Enum, int nEnum> 00050 class NamedEnum 00051 : 00052 public HashTable<int> 00053 { 00054 // Private Member Functions 00055 00056 //- Disallow default bitwise copy construct 00057 NamedEnum(const NamedEnum&); 00058 00059 //- Disallow default bitwise assignment 00060 void operator=(const NamedEnum&); 00061 00062 00063 public: 00064 00065 // Static data members 00066 00067 //- The set of names corresponding to the enumeration Enum 00068 static const char* names[nEnum]; 00069 00070 00071 // Constructors 00072 00073 //- Construct from names 00074 NamedEnum(); 00075 00076 00077 // Member Functions 00078 00079 //- Read a word from Istream and return the corresponding 00080 // enumeration element 00081 const Enum read(Istream& is) const 00082 { 00083 word name(is); 00084 00085 HashTable<int>::const_iterator iter = find(name); 00086 00087 if (iter == HashTable<int>::end()) 00088 { 00089 FatalIOErrorIn 00090 ( 00091 "NamedEnum<Enum, nEnum>::read(Istream& is) const", 00092 is 00093 ) << name << " is not in enumeration " << toc() 00094 << exit(FatalIOError); 00095 } 00096 00097 return Enum(iter()); 00098 } 00099 00100 00101 // Member Operators 00102 00103 //- Return the enumeration element corresponding to the given name 00104 const Enum operator[](const char* name) const 00105 { 00106 return Enum(HashTable<int>::operator[](name)); 00107 } 00108 00109 //- Return the enumeration element corresponding to the given name 00110 const Enum operator[](const word& name) const 00111 { 00112 return Enum(HashTable<int>::operator[](name)); 00113 } 00114 00115 //- Return the name or the given enumeration element 00116 const char* operator[](const Enum e) const 00117 { 00118 return names[e]; 00119 } 00120 }; 00121 00122 00123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00124 00125 } // End namespace Foam 00126 00127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00128 00129 #ifdef NoRepository 00130 # include "NamedEnum.C" 00131 #endif 00132 00133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00134 00135 #endif 00136 00137 // ************************************************************************* //