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

UIndirectListI.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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00027 
00028 template<class T>
00029 inline Foam::UIndirectList<T>::UIndirectList
00030 (
00031     const UList<T>& completeList,
00032     const UList<label>& addr
00033 )
00034 :
00035     completeList_(const_cast<UList<T>&>(completeList)),
00036     addressing_(addr)
00037 {}
00038 
00039 
00040 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00041 
00042 template<class T>
00043 inline Foam::label Foam::UIndirectList<T>::size() const
00044 {
00045     return addressing_.size();
00046 }
00047 
00048 
00049 template<class T>
00050 inline bool Foam::UIndirectList<T>::empty() const
00051 {
00052     return addressing_.empty();
00053 }
00054 
00055 
00056 template<class T>
00057 inline const Foam::UList<T>& Foam::UIndirectList<T>::completeList() const
00058 {
00059     return completeList_;
00060 }
00061 
00062 
00063 template<class T>
00064 inline const Foam::List<Foam::label>& Foam::UIndirectList<T>::addressing() const
00065 {
00066     return addressing_;
00067 }
00068 
00069 
00070 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00071 
00072 template<class T>
00073 inline Foam::List<T> Foam::UIndirectList<T>::operator()() const
00074 {
00075     List<T> result(size());
00076 
00077     forAll(*this, i)
00078     {
00079         result[i] = operator[](i);
00080     }
00081 
00082     return result;
00083 }
00084 
00085 
00086 template<class T>
00087 inline T& Foam::UIndirectList<T>::operator[](const label i)
00088 {
00089     return completeList_[addressing_[i]];
00090 }
00091 
00092 
00093 template<class T>
00094 inline const T& Foam::UIndirectList<T>::operator[](const label i) const
00095 {
00096     return completeList_[addressing_[i]];
00097 }
00098 
00099 
00100 template<class T>
00101 inline void Foam::UIndirectList<T>::operator=(const UList<T>& ae)
00102 {
00103     if (addressing_.size() != ae.size())
00104     {
00105         FatalErrorIn("UIndirectList<T>::operator=(const UList<T>&)")
00106             << "Addressing and list of addressed elements "
00107                "have different sizes: "
00108             << addressing_.size() << " " << ae.size()
00109             << abort(FatalError);
00110     }
00111 
00112     forAll(addressing_, i)
00113     {
00114         completeList_[addressing_[i]] = ae[i];
00115     }
00116 }
00117 
00118 
00119 template<class T>
00120 inline void Foam::UIndirectList<T>::operator=(const T& t)
00121 {
00122     forAll(addressing_, i)
00123     {
00124         completeList_[addressing_[i]] = t;
00125     }
00126 }
00127 
00128 
00129 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines