UIndirectListI.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 | Copyright (C) 2011-2015 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 completeList_;
88 }
89 
90 
91 template<class T>
93 {
94  return addressing_;
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
99 
100 template<class T>
102 {
103  List<T> result(size());
104 
105  forAll(*this, i)
106  {
107  result[i] = operator[](i);
108  }
109 
110  return result;
111 }
112 
113 
114 template<class T>
116 {
117  return completeList_[addressing_[i]];
118 }
119 
120 
121 template<class T>
122 inline const T& Foam::UIndirectList<T>::operator[](const label i) const
123 {
124  return completeList_[addressing_[i]];
125 }
126 
127 
128 template<class T>
130 {
131  if (addressing_.size() != ae.size())
132  {
134  << "Addressing and list of addressed elements "
135  "have different sizes: "
136  << addressing_.size() << " " << ae.size()
137  << abort(FatalError);
138  }
139 
140  forAll(addressing_, i)
141  {
142  completeList_[addressing_[i]] = ae[i];
143  }
144 }
145 
146 
147 template<class T>
149 {
150  if (addressing_.size() != ae.size())
151  {
153  << "Addressing and list of addressed elements "
154  "have different sizes: "
155  << addressing_.size() << " " << ae.size()
156  << abort(FatalError);
157  }
158 
159  forAll(addressing_, i)
160  {
161  completeList_[addressing_[i]] = ae[i];
162  }
163 }
164 
165 
166 template<class T>
168 {
169  forAll(addressing_, i)
170  {
171  completeList_[addressing_[i]] = t;
172  }
173 }
174 
175 
176 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:319
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
const List< label > & addressing() const
Return the list addressing.
bool empty() const
Return true if the list is empty (ie, size() is zero).
label size() const
Return the number of elements in the list.
const UList< T > & completeList() const
Return the complete 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.
List< T > operator()() const
Return the addressed elements as a List.
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
A List with indirect addressing.
Definition: fvMatrix.H:106
void operator=(const UList< T > &)
Assignment from UList of addressed elements.
UIndirectList(const UList< T > &, const labelUList &)
Construct given the complete list and the addressing array.
T & operator[](const label)
Return non-const access to an element.