UIndirectListI.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-2020 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>& completeList,
32  const labelUList& addr
33 )
34 :
35  completeList_(const_cast<UList<T>&>(completeList)),
36  addressing_(addr)
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
42 template<class T>
44 {
45  return addressing_.size();
46 }
47 
48 
49 template<class T>
50 inline bool Foam::UIndirectList<T>::empty() const
51 {
52  return addressing_.empty();
53 }
54 
55 
56 template<class T>
58 {
59  return completeList_[addressing_.first()];
60 }
61 
62 
63 template<class T>
64 inline const T& Foam::UIndirectList<T>::first() const
65 {
66  return completeList_[addressing_.first()];
67 }
68 
69 
70 template<class T>
72 {
73  return completeList_[addressing_.last()];
74 }
75 
76 
77 template<class T>
78 inline const T& Foam::UIndirectList<T>::last() const
79 {
80  return completeList_[addressing_.last()];
81 }
82 
83 
84 template<class T>
86 {
87  return addressing_.fcIndex(i);
88 }
89 
90 
91 template<class T>
93 {
94  return addressing_.rcIndex(i);
95 }
96 
97 
98 template<class T>
100 {
101  return completeList_;
102 }
103 
104 
105 template<class T>
107 {
108  return addressing_;
109 }
110 
111 
112 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
113 
114 template<class T>
116 {
117  List<T> result(size());
118 
119  forAll(*this, i)
120  {
121  result[i] = operator[](i);
122  }
123 
124  return result;
125 }
126 
127 
128 template<class T>
130 {
131  return completeList_[addressing_[i]];
132 }
133 
134 
135 template<class T>
136 inline const T& Foam::UIndirectList<T>::operator[](const label i) const
137 {
138  return completeList_[addressing_[i]];
139 }
140 
141 
142 template<class T>
144 {
145  if (addressing_.size() != ae.size())
146  {
148  << "Addressing and list of addressed elements "
149  "have different sizes: "
150  << addressing_.size() << " " << ae.size()
151  << abort(FatalError);
152  }
153 
154  forAll(addressing_, i)
155  {
156  completeList_[addressing_[i]] = ae[i];
157  }
158 }
159 
160 
161 template<class T>
163 {
164  if (addressing_.size() != ae.size())
165  {
167  << "Addressing and list of addressed elements "
168  "have different sizes: "
169  << addressing_.size() << " " << ae.size()
170  << abort(FatalError);
171  }
172 
173  forAll(addressing_, i)
174  {
175  completeList_[addressing_[i]] = ae[i];
176  }
177 }
178 
179 
180 template<class T>
182 {
183  forAll(addressing_, i)
184  {
185  completeList_[addressing_[i]] = t;
186  }
187 }
188 
189 
190 // ************************************************************************* //
#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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
label size() const
Return the number of elements in the list.
const UList< T > & completeList() const
Return the complete list.
List< T > operator()() const
Return the addressed elements as a List.
T & last()
Return the last element of the 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 volScalarField & T
T & first()
Return the first element of the list.
A List with indirect addressing.
Definition: fvMatrix.H:106
void operator=(const UList< T > &)
Assignment to UList of addressed elements.
UIndirectList(const UList< T > &, const labelUList &)
Construct given the complete list and the addressing array.
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
bool empty() const
Return true if the list is empty (ie, size() is zero).
T & operator[](const label)
Return non-const access to an element.
const List< label > & addressing() const
Return the list addressing.