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

BiIndirectListI.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::BiIndirectList<T>::BiIndirectList
00030 (
00031     const UList<T>& posList,
00032     const UList<T>& negList,
00033     const UList<label>& addr
00034 )
00035 :
00036     posList_(const_cast<UList<T>&>(posList)),
00037     negList_(const_cast<UList<T>&>(negList)),
00038     addressing_(addr)
00039 {}
00040 
00041 
00042 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00043 
00044 template<class T>
00045 inline Foam::label Foam::BiIndirectList<T>::size() const
00046 {
00047     return addressing_.size();
00048 }
00049 
00050 
00051 template<class T>
00052 inline bool Foam::BiIndirectList<T>::empty() const
00053 {
00054     return addressing_.empty();
00055 }
00056 
00057 
00058 template<class T>
00059 inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const
00060 {
00061     return posList_;
00062 }
00063 
00064 
00065 template<class T>
00066 inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const
00067 {
00068     return negList_;
00069 }
00070 
00071 
00072 template<class T>
00073 inline const Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
00074  const
00075 {
00076     return addressing_;
00077 }
00078 
00079 
00080 template<class T>
00081 inline Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
00082 {
00083     return addressing_;
00084 }
00085 
00086 
00087 template<class T>
00088 inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
00089 {
00090     return i;
00091 }
00092 
00093 
00094 template<class T>
00095 inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
00096 {
00097     return -i-1;
00098 }
00099 
00100 
00101 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00102 
00103 template<class T>
00104 inline Foam::List<T> Foam::BiIndirectList<T>::operator()() const
00105 {
00106     List<T> result(size());
00107 
00108     forAll(*this, i)
00109     {
00110         result[i] = operator[](i);
00111     }
00112 
00113     return result;
00114 }
00115 
00116 
00117 template<class T>
00118 inline T& Foam::BiIndirectList<T>::operator[](const label i)
00119 {
00120     label index = addressing_[i];
00121 
00122     if (index >= 0)
00123     {
00124         return posList_[index];
00125     }
00126     else
00127     {
00128         return negList_[-index-1];
00129     }
00130 }
00131 
00132 
00133 template<class T>
00134 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
00135 {
00136     label index = addressing_[i];
00137 
00138     if (index >= 0)
00139     {
00140         return posList_[index];
00141     }
00142     else
00143     {
00144         return negList_[-index-1];
00145     }
00146 }
00147 
00148 
00149 template<class T>
00150 inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
00151 {
00152     if (addressing_.size() != ae.size())
00153     {
00154         FatalErrorIn("BiIndirectList<T>::operator=(const UList<T>&)")
00155             << "Addressing and list of addressed elements "
00156                "have different sizes: "
00157             << addressing_.size() << " " << ae.size()
00158             << abort(FatalError);
00159     }
00160 
00161     forAll(addressing_, i)
00162     {
00163         operator[](i) = ae[i];
00164     }
00165 }
00166 
00167 
00168 template<class T>
00169 inline void Foam::BiIndirectList<T>::operator=(const T& t)
00170 {
00171     forAll(addressing_, i)
00172     {
00173         operator[](i) = t;
00174     }
00175 }
00176 
00177 
00178 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines