BiIndirectListI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class T>
30 (
31  const UList<T>& posList,
32  const UList<T>& negList,
33  const labelUList& addr
34 )
35 :
36  posList_(const_cast<UList<T>&>(posList)),
37  negList_(const_cast<UList<T>&>(negList)),
38  addressing_(addr)
39 {}
40 
41 
42 template<class T>
44 (
45  const UList<T>& posList,
46  const UList<T>& negList,
47  List<label>&& addr
48 )
49 :
50  posList_(const_cast<UList<T>&>(posList)),
51  negList_(const_cast<UList<T>&>(negList)),
52  addressing_(move(addr))
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
58 template<class T>
60 {
61  return addressing_.size();
62 }
63 
64 
65 template<class T>
66 inline bool Foam::BiIndirectList<T>::empty() const
67 {
68  return addressing_.empty();
69 }
70 
71 
72 template<class T>
74 {
75  return posList_;
76 }
77 
78 
79 template<class T>
81 {
82  return negList_;
83 }
84 
85 
86 template<class T>
88  const
89 {
90  return addressing_;
91 }
92 
93 
94 template<class T>
96 (
97  const labelUList& addr
98 )
99 {
100  addressing_ = addr;
101 }
102 
103 
104 template<class T>
106 {
107  return i;
108 }
109 
110 
111 template<class T>
113 {
114  return -i-1;
115 }
116 
117 
118 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
119 
120 template<class T>
122 {
123  List<T> result(size());
124 
125  forAll(*this, i)
126  {
127  result[i] = operator[](i);
128  }
129 
130  return result;
131 }
132 
133 
134 template<class T>
136 {
137  label index = addressing_[i];
138 
139  if (index >= 0)
140  {
141  return posList_[index];
142  }
143  else
144  {
145  return negList_[-index-1];
146  }
147 }
148 
149 
150 template<class T>
151 inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
152 {
153  label index = addressing_[i];
154 
155  if (index >= 0)
156  {
157  return posList_[index];
158  }
159  else
160  {
161  return negList_[-index-1];
162  }
163 }
164 
165 
166 template<class T>
168 {
169  if (addressing_.size() != ae.size())
170  {
172  << "Addressing and list of addressed elements "
173  "have different sizes: "
174  << addressing_.size() << " " << ae.size()
175  << abort(FatalError);
176  }
177 
178  addressing_ = move(ae);
179 }
180 
181 
182 template<class T>
184 {
185  if (addressing_.size() != ae.size())
186  {
188  << "Addressing and list of addressed elements "
189  "have different sizes: "
190  << addressing_.size() << " " << ae.size()
191  << abort(FatalError);
192  }
193 
194  forAll(addressing_, i)
195  {
196  operator[](i) = ae[i];
197  }
198 }
199 
200 
201 template<class T>
203 {
204  forAll(addressing_, i)
205  {
206  operator[](i) = t;
207  }
208 }
209 
210 
211 // ************************************************************************* //
label size() const
Return the number of elements in the list.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
BiIndirectList(const UList< T > &posList, const UList< T > &negList, const labelUList &)
Construct given the complete lists and the addressing array.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
static label negIndex(const label)
T & operator[](const label)
Return non-const access to an element.
static label posIndex(const label)
Calculate index given whether index is into posList or negList.
bool empty() const
Return true if the list is empty (ie, size() is zero).
void operator=(List< T > &&)
Move assignment to List of addressed elements.
void resetAddressing(const labelUList &)
Reset addressing.
List< T > operator()() const
Return the addressed elements as a List.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const UList< T > & negList() const
const UList< T > & posList() const
const volScalarField & T
const List< label > & addressing() const
Return the list addressing.
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299