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 #include "HashPtrTable.H"
00027 #include <OpenFOAM/Istream.H>
00028 #include <OpenFOAM/Ostream.H>
00029 #include <OpenFOAM/INew.H>
00030
00031
00032
00033 template<class T, class Key, class Hash>
00034 template<class INew>
00035 void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
00036 {
00037 is.fatalCheck("HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)");
00038
00039 token firstToken(is);
00040
00041 is.fatalCheck
00042 (
00043 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&) : "
00044 "reading first token"
00045 );
00046
00047 if (firstToken.isLabel())
00048 {
00049 label s = firstToken.labelToken();
00050
00051
00052 char delimiter = is.readBeginList("HashPtrTable<T, Key, Hash>");
00053
00054 if (s)
00055 {
00056 if (2*s > this->tableSize_)
00057 {
00058 this->resize(2*s);
00059 }
00060
00061 if (delimiter == token::BEGIN_LIST)
00062 {
00063 for (label i=0; i<s; i++)
00064 {
00065 Key key;
00066 is >> key;
00067 this->insert(key, inewt(key, is).ptr());
00068
00069 is.fatalCheck
00070 (
00071 "HashPtrTable<T, Key, Hash>::"
00072 "read(Istream&, const INew&) : reading entry"
00073 );
00074 }
00075 }
00076 else
00077 {
00078 FatalIOErrorIn
00079 (
00080 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)",
00081 is
00082 ) << "incorrect first token, '(', found " << firstToken.info()
00083 << exit(FatalIOError);
00084 }
00085 }
00086
00087
00088 is.readEndList("HashPtrTable");
00089 }
00090 else if (firstToken.isPunctuation())
00091 {
00092 if (firstToken.pToken() != token::BEGIN_LIST)
00093 {
00094 FatalIOErrorIn
00095 (
00096 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)",
00097 is
00098 ) << "incorrect first token, '(', found " << firstToken.info()
00099 << exit(FatalIOError);
00100 }
00101
00102 token lastToken(is);
00103 while
00104 (
00105 !(
00106 lastToken.isPunctuation()
00107 && lastToken.pToken() == token::END_LIST
00108 )
00109 )
00110 {
00111 is.putBack(lastToken);
00112 Key key;
00113 is >> key;
00114 this->insert(key, inewt(key, is).ptr());
00115
00116 is.fatalCheck
00117 (
00118 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&) : "
00119 "reading entry"
00120 );
00121
00122 is >> lastToken;
00123 }
00124 }
00125 else
00126 {
00127 FatalIOErrorIn
00128 (
00129 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)",
00130 is
00131 ) << "incorrect first token, expected <int> or '(', found "
00132 << firstToken.info()
00133 << exit(FatalIOError);
00134 }
00135
00136 is.fatalCheck("HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)");
00137 }
00138
00139
00140
00141
00142 template<class T, class Key, class Hash>
00143 template<class INew>
00144 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is, const INew& inewt)
00145 {
00146 read(is, inewt);
00147 }
00148
00149
00150 template<class T, class Key, class Hash>
00151 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is)
00152 {
00153 read(is, INew<T>());
00154 }
00155
00156
00157
00158
00159 template<class T, class Key, class Hash>
00160 Foam::Istream& Foam::operator>>(Istream& is, HashPtrTable<T, Key, Hash>& L)
00161 {
00162 L.clear();
00163 L.read(is, INew<T>());
00164
00165 return is;
00166 }
00167
00168
00169 template<class T, class Key, class Hash>
00170 Foam::Ostream& Foam::operator<<
00171 (
00172 Ostream& os,
00173 const HashPtrTable<T, Key, Hash>& L
00174 )
00175 {
00176
00177 os << nl << L.size() << nl << token::BEGIN_LIST << nl;
00178
00179
00180 for
00181 (
00182 typename HashPtrTable<T, Key, Hash>::const_iterator iter = L.begin();
00183 iter != L.end();
00184 ++iter
00185 )
00186 {
00187 os << iter.key() << token::SPACE << *iter() << nl;
00188 }
00189
00190
00191 os << token::END_LIST;
00192
00193
00194 os.check("Ostream& operator<<(Ostream&, const HashPtrTable&)");
00195
00196 return os;
00197 }
00198
00199
00200