initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / BiIndirectList / BiIndirectListI.H
blobb30769d107b574a895a1e281cab9a38301ea459b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
29 template<class T>
30 inline Foam::BiIndirectList<T>::BiIndirectList
32     const UList<T>& posList,
33     const UList<T>& negList,
34     const UList<label>& addr
37     posList_(const_cast<UList<T>&>(posList)),
38     negList_(const_cast<UList<T>&>(negList)),
39     addressing_(addr)
43 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
45 template<class T>
46 inline Foam::label Foam::BiIndirectList<T>::size() const
48     return addressing_.size();
52 template<class T>
53 inline bool Foam::BiIndirectList<T>::empty() const
55     return addressing_.empty();
59 template<class T>
60 inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const
62     return posList_;
66 template<class T>
67 inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const
69     return negList_;
73 template<class T>
74 inline const Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
75  const
77     return addressing_;
81 template<class T>
82 inline Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
84     return addressing_;
88 template<class T>
89 inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
91     return i;
95 template<class T>
96 inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
98     return -i-1;
102 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
104 template<class T>
105 inline Foam::List<T> Foam::BiIndirectList<T>::operator()() const
107     List<T> result(size());
109     forAll(*this, i)
110     {
111         result[i] = operator[](i);
112     }
114     return result;
118 template<class T>
119 inline T& Foam::BiIndirectList<T>::operator[](const label i)
121     label index = addressing_[i];
123     if (index >= 0)
124     {
125         return posList_[index];
126     }
127     else
128     {
129         return negList_[-index-1];
130     }
134 template<class T>
135 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
137     label index = addressing_[i];
139     if (index >= 0)
140     {
141         return posList_[index];
142     }
143     else
144     {
145         return negList_[-index-1];
146     }
150 template<class T>
151 inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
153     if (addressing_.size() != ae.size())
154     {
155         FatalErrorIn("BiIndirectList<T>::operator=(const UList<T>&)")
156             << "Addressing and list of addressed elements "
157                "have different sizes: "
158             << addressing_.size() << " " << ae.size()
159             << abort(FatalError);
160     }
162     forAll(addressing_, i)
163     {
164         operator[](i) = ae[i];
165     }
169 template<class T>
170 inline void Foam::BiIndirectList<T>::operator=(const T& t)
172     forAll(addressing_, i)
173     {
174         operator[](i) = t;
175     }
179 // ************************************************************************* //