BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / containers / Lists / BiIndirectList / BiIndirectListI.H
blob88eae210a59eb7d7a589c2ca51a2b94257d1cb5d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
28 template<class T>
29 inline Foam::BiIndirectList<T>::BiIndirectList
31     const UList<T>& posList,
32     const UList<T>& negList,
33     const labelUList& addr
36     posList_(const_cast<UList<T>&>(posList)),
37     negList_(const_cast<UList<T>&>(negList)),
38     addressing_(addr)
42 template<class T>
43 inline Foam::BiIndirectList<T>::BiIndirectList
45     const UList<T>& posList,
46     const UList<T>& negList,
47     const Xfer<List<label> >& addr
50     posList_(const_cast<UList<T>&>(posList)),
51     negList_(const_cast<UList<T>&>(negList)),
52     addressing_(addr)
56 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
58 template<class T>
59 inline Foam::label Foam::BiIndirectList<T>::size() const
61     return addressing_.size();
65 template<class T>
66 inline bool Foam::BiIndirectList<T>::empty() const
68     return addressing_.empty();
72 template<class T>
73 inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const
75     return posList_;
79 template<class T>
80 inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const
82     return negList_;
86 template<class T>
87 inline const Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing()
88  const
90     return addressing_;
94 template<class T>
95 inline void Foam::BiIndirectList<T>::resetAddressing
97     const labelUList& addr
100     addressing_ = addr;
104 template<class T>
105 inline void Foam::BiIndirectList<T>::resetAddressing
107     const Xfer<List<label> >& addr
110     addressing_.transfer(addr());
114 template<class T>
115 inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
117     return i;
121 template<class T>
122 inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
124     return -i-1;
128 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
130 template<class T>
131 inline Foam::List<T> Foam::BiIndirectList<T>::operator()() const
133     List<T> result(size());
135     forAll(*this, i)
136     {
137         result[i] = operator[](i);
138     }
140     return result;
144 template<class T>
145 inline T& Foam::BiIndirectList<T>::operator[](const label i)
147     label index = addressing_[i];
149     if (index >= 0)
150     {
151         return posList_[index];
152     }
153     else
154     {
155         return negList_[-index-1];
156     }
160 template<class T>
161 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
163     label index = addressing_[i];
165     if (index >= 0)
166     {
167         return posList_[index];
168     }
169     else
170     {
171         return negList_[-index-1];
172     }
176 template<class T>
177 inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
179     if (addressing_.size() != ae.size())
180     {
181         FatalErrorIn("BiIndirectList<T>::operator=(const UList<T>&)")
182             << "Addressing and list of addressed elements "
183                "have different sizes: "
184             << addressing_.size() << " " << ae.size()
185             << abort(FatalError);
186     }
188     forAll(addressing_, i)
189     {
190         operator[](i) = ae[i];
191     }
195 template<class T>
196 inline void Foam::BiIndirectList<T>::operator=(const T& t)
198     forAll(addressing_, i)
199     {
200         operator[](i) = t;
201     }
205 // ************************************************************************* //