initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Identifiers / Keyed / KeyedI.H
blob66af277d7826ef1720047f1c2bd8b0cc26fd295b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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  * * * * * * * * * * * * * * //
33 template<class T>
34 inline Foam::Keyed<T>::Keyed()
36     key_(-1)
40 template<class T>
41 inline Foam::Keyed<T>::Keyed(const T& item, const label key)
43     T(item),
44     key_(key)
48 template<class T>
49 inline Foam::Keyed<T>::Keyed(const Xfer<T>& item, const label key)
51     T(item),
52     key_(key)
56 template<class T>
57 inline Foam::Keyed<T>::Keyed(Istream& is)
59     is >> *this;
63 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
65 template<class T>
66 inline Foam::label Foam::Keyed<T>::key() const
68     return key_;
71 template<class T>
72 inline Foam::label& Foam::Keyed<T>::key()
74     return key_;
78 template<class T>
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());
84     forAll (lst, elemI)
85     {
86         newList[elemI] = Keyed(lst[elemI], key);
87     }
88     return newList;
92 template<class T>
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())
97     {
98         FatalErrorIn
99         (
100             "Foam::Keyed<T>::createList(const List<T>&, const List<label>&)"
101         )
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);
106     }
108     List<Keyed<T> > newList(lst.size());
110     forAll (lst, elemI)
111     {
112         newList[elemI] = Keyed(lst[elemI], keys[elemI]);
113     }
114     return newList;
118 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
120 template<class T>
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);
127     is >> item.key_;
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&)");
135     return is;
139 template<class T>
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_
145         << token::END_LIST;
147     return os;
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 // ************************************************************************* //