OpenFOAM logo
Open Source CFD Toolkit

IndirectListI.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-2005 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 //- Construct given size
00032 template<class T>
00033 inline Foam::IndirectList<T>::IndirectList
00034 (
00035     const Foam::UList<T>& completeList,
00036     const Foam::List<label>& addr
00037 )
00038 :
00039     completeList_(completeList),
00040     addressing_(addr)
00041 {}
00042 
00043 
00044 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00045 
00046 template<class T>
00047 inline Foam::label Foam::IndirectList<T>::size() const
00048 {
00049     return addressing_.size();
00050 }
00051 
00052 
00053 template<class T>
00054 inline const Foam::UList<T>& Foam::IndirectList<T>::
00055 completeList() const
00056 {
00057     return completeList_;
00058 }
00059 
00060 
00061 template<class T>
00062 inline const Foam::List<Foam::label>& Foam::IndirectList<T>::addressing() const
00063 {
00064     return addressing_;
00065 }
00066 
00067 
00068 template<class T>
00069 inline void Foam::IndirectList<T>::resetAddressing
00070 (
00071     const List<label>& addr
00072 )
00073 {
00074     addressing_ = addr;
00075 }
00076 
00077 
00078 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00079 
00080 template<class T>
00081 inline Foam::List<T> Foam::IndirectList<T>::operator()() const
00082 {
00083     List<T> result(size());
00084 
00085     forAll(*this, i)
00086     {
00087         result[i] = operator[](i);
00088     }
00089 
00090     return result;
00091 }
00092 
00093 
00094 template<class T>
00095 inline const T& Foam::IndirectList<T>::operator[](const Foam::label i) const
00096 {
00097     return completeList_[addressing_[i]];
00098 }
00099 
00100 
00101 // * * * * * * * * * * * * * * * Ostream Operator *  * * * * * * * * * * * * //
00102 
00103 template<class T>
00104 Foam::Ostream& Foam::operator<<(Ostream& os, const IndirectList<T>& L)
00105 {
00106     // Write size of list and start contents delimiter
00107     os << nl << L.size() << nl << token::BEGIN_LIST;
00108 
00109     // Write list contents
00110     forAll(L, i)
00111     {
00112         os << nl << L[i];
00113     }
00114 
00115     // Write end of contents delimiter
00116     os << nl << token::END_LIST << nl;
00117 
00118     return os;
00119 }
00120 
00121 // ************************************************************************* //
For further information go to www.openfoam.org