FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

KeyedI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/IOstreams.H>
00027 
00028 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 template<class T>
00033 inline Foam::Keyed<T>::Keyed()
00034 :
00035     key_(-1)
00036 {}
00037 
00038 
00039 template<class T>
00040 inline Foam::Keyed<T>::Keyed(const T& item, const label key)
00041 :
00042     T(item),
00043     key_(key)
00044 {}
00045 
00046 
00047 template<class T>
00048 inline Foam::Keyed<T>::Keyed(const Xfer<T>& item, const label key)
00049 :
00050     T(item),
00051     key_(key)
00052 {}
00053 
00054 
00055 template<class T>
00056 inline Foam::Keyed<T>::Keyed(Istream& is)
00057 {
00058     is >> *this;
00059 }
00060 
00061 
00062 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00063 
00064 template<class T>
00065 inline Foam::label Foam::Keyed<T>::key() const
00066 {
00067     return key_;
00068 }
00069 
00070 template<class T>
00071 inline Foam::label& Foam::Keyed<T>::key()
00072 {
00073     return key_;
00074 }
00075 
00076 
00077 template<class T>
00078 inline Foam::List<Foam::Keyed<T> >
00079 Foam::Keyed<T>::createList(const List<T>& lst, const label key)
00080 {
00081     List<Keyed<T> > newList(lst.size());
00082 
00083     forAll (lst, elemI)
00084     {
00085         newList[elemI] = Keyed(lst[elemI], key);
00086     }
00087     return newList;
00088 }
00089 
00090 
00091 template<class T>
00092 inline Foam::List<Foam::Keyed<T> >
00093 Foam::Keyed<T>::createList(const List<T>& lst, const List<label>& keys)
00094 {
00095     if (lst.size() != keys.size())
00096     {
00097         FatalErrorIn
00098         (
00099             "Foam::Keyed<T>::createList(const List<T>&, const List<label>&)"
00100         )
00101             << "size mismatch adding keys to a list:" << nl
00102             << "List has size " << lst.size()
00103             << " and keys has size " << keys.size() << nl
00104             << abort(FatalError);
00105     }
00106 
00107     List<Keyed<T> > newList(lst.size());
00108 
00109     forAll (lst, elemI)
00110     {
00111         newList[elemI] = Keyed(lst[elemI], keys[elemI]);
00112     }
00113     return newList;
00114 }
00115 
00116 
00117 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00118 
00119 template<class T>
00120 inline Foam::Istream& Foam::operator>>(Istream& is, Keyed<T>& item)
00121 {
00122     // Read beginning of Keyed item/key pair
00123     is.readBegin("Keyed<T>");
00124 
00125     is >> static_cast<T&>(item);
00126     is >> item.key_;
00127 
00128     // Read end of Keyed item/key pair
00129     is.readEnd("Keyed<T>");
00130 
00131     // Check state of Ostream
00132     is.check("Istream& operator>>(Istream&, Keyed&)");
00133 
00134     return is;
00135 }
00136 
00137 
00138 template<class T>
00139 inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed<T>& item)
00140 {
00141     os  << token::BEGIN_LIST
00142         << static_cast<const T&>(item)
00143         << token::SPACE << item.key_
00144         << token::END_LIST;
00145 
00146     return os;
00147 }
00148 
00149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00150 
00151 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines