1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "HashPtrTable.H"
32 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34 template<class T, class Key, class Hash>
36 void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt)
38 is.fatalCheck("HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)");
44 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&) : "
48 if (firstToken.isLabel())
50 label s = firstToken.labelToken();
52 // Read beginning of contents
53 char delimiter = is.readBeginList("HashPtrTable<T, Key, Hash>");
57 if (2*s > this->tableSize_)
62 if (delimiter == token::BEGIN_LIST)
64 for (label i=0; i<s; i++)
68 insert(key, inewt(key, is).ptr());
72 "HashPtrTable<T, Key, Hash>::"
73 "read(Istream&, const INew&) : reading entry"
81 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)",
83 ) << "incorrect first token, '(', found " << firstToken.info()
84 << exit(FatalIOError);
88 // Read end of contents
89 is.readEndList("HashPtrTable");
91 else if (firstToken.isPunctuation())
93 if (firstToken.pToken() != token::BEGIN_LIST)
97 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)",
99 ) << "incorrect first token, '(', found " << firstToken.info()
100 << exit(FatalIOError);
107 lastToken.isPunctuation()
108 && lastToken.pToken() == token::END_LIST
112 is.putBack(lastToken);
115 insert(key, inewt(key, is).ptr());
119 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&) : "
130 "HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)",
132 ) << "incorrect first token, expected <int> or '(', found "
134 << exit(FatalIOError);
137 is.fatalCheck("HashPtrTable<T, Key, Hash>::read(Istream&, const INew&)");
141 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
143 template<class T, class Key, class Hash>
145 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is, const INew& inewt)
151 template<class T, class Key, class Hash>
152 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(Istream& is)
158 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
160 template<class T, class Key, class Hash>
161 Foam::Istream& Foam::operator>>(Istream& is, HashPtrTable<T, Key, Hash>& L)
164 L.read(is, INew<T>());
170 template<class T, class Key, class Hash>
171 Foam::Ostream& Foam::operator<<
174 const HashPtrTable<T, Key, Hash>& L
177 // Write size and start delimiter
178 os << nl << L.size() << nl << token::BEGIN_LIST << nl;
183 typename HashPtrTable<T, Key, Hash>::const_iterator iter = L.begin();
188 os << iter.key() << token::SPACE << *iter() << nl;
191 // Write end delimiter
192 os << token::END_LIST;
194 // Check state of IOstream
195 os.check("Ostream& operator<<(Ostream&, const HashPtrTable&)");
201 // ************************************************************************* //