OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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