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 "IOstreams.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 inline Foam::Keyed<T>::Keyed()
41 inline Foam::Keyed<T>::Keyed(const T& item, const label key)
49 inline Foam::Keyed<T>::Keyed(const Xfer<T>& item, const label key)
57 inline Foam::Keyed<T>::Keyed(Istream& is)
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 inline Foam::label Foam::Keyed<T>::key() const
72 inline Foam::label& Foam::Keyed<T>::key()
79 inline Foam::List<Foam::Keyed<T> >
80 Foam::Keyed<T>::createList(const List<T>& lst, const label key)
82 List<Keyed<T> > newList(lst.size());
86 newList[elemI] = Keyed(lst[elemI], key);
93 inline Foam::List<Foam::Keyed<T> >
94 Foam::Keyed<T>::createList(const List<T>& lst, const List<label>& keys)
96 if (lst.size() != keys.size())
100 "Foam::Keyed<T>::createList(const List<T>&, const List<label>&)"
102 << "size mismatch adding keys to a list:" << nl
103 << "List has size " << lst.size()
104 << " and keys has size " << keys.size() << nl
105 << abort(FatalError);
108 List<Keyed<T> > newList(lst.size());
112 newList[elemI] = Keyed(lst[elemI], keys[elemI]);
118 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
121 inline Foam::Istream& Foam::operator>>(Istream& is, Keyed<T>& item)
123 // Read beginning of Keyed item/key pair
124 is.readBegin("Keyed<T>");
126 is >> static_cast<T&>(item);
129 // Read end of Keyed item/key pair
130 is.readEnd("Keyed<T>");
132 // Check state of Ostream
133 is.check("Istream& operator>>(Istream&, Keyed&)");
140 inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed<T>& item)
142 os << token::BEGIN_LIST
143 << static_cast<const T&>(item)
144 << token::SPACE << item.key_
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 // ************************************************************************* //