OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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 List<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 const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const
00054 {
00055     return posList_;
00056 }
00057 
00058 
00059 template<class T>
00060 inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const
00061 {
00062     return negList_;
00063 }
00064 
00065 
00066 template<class T>
00067 inline const Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
00068  const
00069 {
00070     return addressing_;
00071 }
00072 
00073 
00074 template<class T>
00075 inline Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
00076 {
00077     return addressing_;
00078 }
00079 
00080 
00081 template<class T>
00082 inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
00083 {
00084     return i;
00085 }
00086 
00087 
00088 template<class T>
00089 inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
00090 {
00091     return -i-1;
00092 }
00093 
00094 
00095 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00096 
00097 template<class T>
00098 inline Foam::List<T> Foam::BiIndirectList<T>::operator()() const
00099 {
00100     List<T> result(size());
00101 
00102     forAll(*this, i)
00103     {
00104         result[i] = operator[](i);
00105     }
00106 
00107     return result;
00108 }
00109 
00110 
00111 template<class T>
00112 inline T& Foam::BiIndirectList<T>::operator[](const label i)
00113 {
00114     label index = addressing_[i];
00115 
00116     if (index >= 0)
00117     {
00118         return posList_[index];
00119     }
00120     else
00121     {
00122         return negList_[-index-1];
00123     }
00124 }
00125 
00126 
00127 template<class T>
00128 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
00129 {
00130     label index = addressing_[i];
00131 
00132     if (index >= 0)
00133     {
00134         return posList_[index];
00135     }
00136     else
00137     {
00138         return negList_[-index-1];
00139     }
00140 }
00141 
00142 
00143 template<class T>
00144 inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
00145 {
00146     if (addressing_.size() != ae.size())
00147     {
00148         FatalErrorIn("BiIndirectList<T>::operator=(const UList<T>&)")
00149             << "Addressing and list of addressed elements "
00150                "have different sizes: "
00151             << addressing_.size() << " " << ae.size()
00152             << abort(FatalError);
00153     }
00154 
00155     forAll(addressing_, i)
00156     {
00157         operator[](i) = ae[i];
00158     }
00159 }
00160 
00161 
00162 template<class T>
00163 inline void Foam::BiIndirectList<T>::operator=(const T& t)
00164 {
00165     forAll(addressing_, i)
00166     {
00167         operator[](i) = t;
00168     }
00169 }
00170 
00171 
00172 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd