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