NamedEnum.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "NamedEnum.H"
00028 #include "stringList.H"
00029
00030
00031
00032 template<class Enum, int nEnum>
00033 Foam::NamedEnum<Enum, nEnum>::NamedEnum()
00034 :
00035 HashTable<int>(2*nEnum)
00036 {
00037 for (int i=0; i<nEnum; i++)
00038 {
00039 if (!names[i] || names[i][0] == '\0')
00040 {
00041 stringList goodNames(i);
00042
00043 for (int j = 0; j < i; j++)
00044 {
00045 goodNames[j] = names[j];
00046 }
00047
00048 FatalErrorIn("NamedEnum<Enum, nEnum>::NamedEnum()")
00049 << "Illegal enumeration name at position " << i << endl
00050 << "after entries " << goodNames << ".\n"
00051 << "Possibly your NamedEnum<Enum, nEnum>::names array"
00052 << " is not of size " << nEnum << endl
00053 << abort(FatalError);
00054 }
00055 insert(names[i], i);
00056 }
00057 }
00058
00059
00060
00061
00062 template<class Enum, int nEnum>
00063 Enum Foam::NamedEnum<Enum, nEnum>::read(Istream& is) const
00064 {
00065 word name(is);
00066
00067 HashTable<int>::const_iterator iter = find(name);
00068
00069 if (iter == HashTable<int>::end())
00070 {
00071 FatalIOErrorIn
00072 (
00073 "NamedEnum<Enum, nEnum>::read(Istream&) const", is
00074 ) << name << " is not in enumeration: "
00075 << toc() << exit(FatalIOError);
00076 }
00077
00078 return Enum(iter());
00079 }
00080
00081
00082 template<class Enum, int nEnum>
00083 void Foam::NamedEnum<Enum, nEnum>::write(const Enum e, Ostream& os) const
00084 {
00085 os << operator[](e);
00086 }
00087
00088
00089
Copyright © 2000-2009 OpenCFD Ltd