BiIndirectListI.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
30
31template<class T>
32inline Foam::label Foam::BiIndirectList<T>::posIndex(const label i)
33{
34 return i;
35}
36
37
38template<class T>
39inline Foam::label Foam::BiIndirectList<T>::negIndex(const label i)
40{
41 return -i-1;
42}
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
47template<class T>
49(
50 const UList<T>& posList,
51 const UList<T>& negList,
52 const labelUList& addr
53)
54:
55 posList_(const_cast<UList<T>&>(posList)),
56 negList_(const_cast<UList<T>&>(negList)),
57 addressing_(addr)
58{}
59
60
61template<class T>
63(
64 const UList<T>& posList,
65 const UList<T>& negList,
66 labelList&& addr
67)
68:
69 posList_(const_cast<UList<T>&>(posList)),
70 negList_(const_cast<UList<T>&>(negList)),
71 addressing_(std::move(addr))
72{}
73
74
75// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76
77template<class T>
78inline Foam::label Foam::BiIndirectList<T>::size() const noexcept
79{
80 return addressing_.size();
81}
82
83
84template<class T>
86{
87 return addressing_.empty();
88}
89
90
91template<class T>
93{
94 return posList_;
95}
96
97
98template<class T>
100{
101 return negList_;
102}
103
104
105template<class T>
106inline const Foam::labelList&
108{
109 return addressing_;
110}
111
112
113template<class T>
115(
116 const labelUList& addr
117)
118{
119 addressing_ = addr;
120}
121
122
123template<class T>
125(
126 labelList&& addr
127)
128{
129 addressing_.transfer(addr);
130}
131
132
133// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
134
135template<class T>
137{
138 List<T> result(size());
139
140 forAll(*this, i)
141 {
142 result[i] = operator[](i);
143 }
144
145 return result;
146}
147
148
149template<class T>
151{
152 const label index = addressing_[i];
153
154 if (index >= 0)
155 {
156 return posList_[index];
157 }
158 else
159 {
160 return negList_[-index-1];
161 }
162}
163
164
165template<class T>
166inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
167{
168 const label index = addressing_[i];
169
170 if (index >= 0)
171 {
172 return posList_[index];
173 }
174 else
175 {
176 return negList_[-index-1];
177 }
178}
179
180
181template<class T>
183{
184 if (addressing_.size() != ae.size())
185 {
187 << "Addressing and list of addressed elements "
188 "have different sizes: "
189 << addressing_.size() << " " << ae.size()
190 << abort(FatalError);
191 }
192
193 forAll(addressing_, i)
194 {
195 operator[](i) = ae[i];
196 }
197}
198
199
200template<class T>
202{
203 forAll(addressing_, i)
204 {
205 operator[](i) = val;
206 }
207}
208
209
210// ************************************************************************* //
Indexes into negList (negative index) or posList (zero or positive index).
const UList< T > & negList() const noexcept
const labelList & addressing() const noexcept
Return the list addressing.
static label posIndex(const label i)
Calculate index given whether index is into posList or negList.
static label negIndex(const label i)
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
const UList< T > & posList() const noexcept
label size() const noexcept
The number of elements in the list.
void operator=(const UList< T > &ae)
Assignment to UList of addressed elements.
void resetAddressing(const labelUList &addr)
Copy reset addressing.
List< T > operator()() const
Return the addressed elements as a List.
T & operator[](const label i)
Return non-const access to an element.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
const volScalarField & T
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
errorManip< error > abort(error &err)
Definition: errorManip.H:144
const direction noexcept
Definition: Scalar.H:223
error FatalError
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333