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

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