UPtrListI.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-2023 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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
28 template<class T>
30 {
31  return ptrs_.size();
32 }
33 
34 
35 template<class T>
36 inline bool Foam::UPtrList<T>::empty() const
37 {
38  return ptrs_.empty();
39 }
40 
41 
42 template<class T>
44 {
45  return this->operator[](0);
46 }
47 
48 
49 template<class T>
50 inline const T& Foam::UPtrList<T>::first() const
51 {
52  return this->operator[](0);
53 }
54 
55 
56 template<class T>
58 {
59  return this->operator[](this->size()-1);
60 }
61 
62 
63 template<class T>
64 inline const T& Foam::UPtrList<T>::last() const
65 {
66  return this->operator[](this->size()-1);
67 }
68 
69 
70 template<class T>
71 inline void Foam::UPtrList<T>::resize(const label newSize)
72 {
73  this->setSize(newSize);
74 }
75 
76 
77 template<class T>
78 inline bool Foam::UPtrList<T>::set(const label i) const
79 {
80  return ptrs_[i] != nullptr;
81 }
82 
83 
84 template<class T>
85 inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
86 {
87  T* old = ptrs_[i];
88  ptrs_[i] = ptr;
89  return old;
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
94 
95 template<class T>
96 inline const T& Foam::UPtrList<T>::operator[](const label i) const
97 {
98  if (!ptrs_[i])
99  {
101  << "hanging pointer at index " << i
102  << " (size " << size()
103  << "), cannot dereference"
104  << abort(FatalError);
105  }
106 
107  return *(ptrs_[i]);
108 }
109 
110 
111 template<class T>
113 {
114  if (!ptrs_[i])
115  {
117  << "hanging pointer at index " << i
118  << " (size " << size()
119  << "), cannot dereference"
120  << abort(FatalError);
121  }
122 
123  return *(ptrs_[i]);
124 }
125 
126 
127 template<class T>
128 inline const T* Foam::UPtrList<T>::operator()(const label i) const
129 {
130  return ptrs_[i];
131 }
132 
133 
134 template<class T>
136 {
137  return ptrs_[i];
138 }
139 
140 
141 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
142 
143 template<class T>
145 :
146  ptr_(ptr)
147 {}
148 
149 
150 template<class T>
151 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
152 {
153  return ptr_ == iter.ptr_;
154 }
155 
156 
157 template<class T>
158 inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
159 {
160  return ptr_ != iter.ptr_;
161 }
162 
163 
164 template<class T>
166 {
167  return **ptr_;
168 }
169 
170 
171 template<class T>
173 {
174  return operator*();
175 }
176 
177 
178 template<class T>
179 inline typename Foam::UPtrList<T>::iterator
181 {
182  ++ptr_;
183  return *this;
184 }
185 
186 
187 template<class T>
188 inline typename Foam::UPtrList<T>::iterator
190 {
191  iterator tmp = *this;
192  ++ptr_;
193  return tmp;
194 }
195 
196 
197 template<class T>
198 inline typename Foam::UPtrList<T>::iterator
200 {
201  --ptr_;
202  return *this;
203 }
204 
205 
206 template<class T>
207 inline typename Foam::UPtrList<T>::iterator
209 {
210  iterator tmp = *this;
211  --ptr_;
212  return tmp;
213 }
214 
215 
216 template<class T>
217 inline typename Foam::UPtrList<T>::iterator
219 {
220  ptr_ += n;
221  return *this;
222 }
223 
224 
225 template<class T>
226 inline typename Foam::UPtrList<T>::iterator
228 {
229  ptr_ -= n;
230  return *this;
231 }
232 
233 
234 template<class T>
237 {
238  typename UPtrList<T>::iterator tmp = *this;
239  return tmp += n;
240 }
241 
242 
243 template<class T>
244 inline typename Foam::UPtrList<T>::iterator
246 {
247  typename UPtrList<T>::iterator tmp = *this;
248  return tmp -= n;
249 }
250 
251 
252 template<class T>
254 (
255  const typename UPtrList<T>::iterator& iter
256 ) const
257 {
258  return (ptr_ - iter.ptr_);
259 }
260 
261 
262 template<class T>
264 {
265  return *(*this + n);
266 }
267 
268 
269 template<class T>
270 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
271 {
272  return ptr_ < iter.ptr_;
273 }
274 
275 
276 template<class T>
277 inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
278 {
279  return ptr_ > iter.ptr_;
280 }
281 
282 
283 template<class T>
284 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
285 {
286  return ptr_ <= iter.ptr_;
287 }
288 
289 
290 template<class T>
291 inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
292 {
293  return ptr_ >= iter.ptr_;
294 }
295 
296 
297 template<class T>
300 {
301  return ptrs_.begin();
302 }
303 
304 
305 template<class T>
306 inline typename Foam::UPtrList<T>::iterator
308 {
309  return ptrs_.end();
310 }
311 
312 
313 // * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
314 
315 template<class T>
317 :
318  ptr_(ptr)
319 {}
320 
321 
322 template<class T>
324 :
325  ptr_(iter.ptr_)
326 {}
327 
328 
329 template<class T>
331 (
332  const const_iterator& iter
333 ) const
334 {
335  return ptr_ == iter.ptr_;
336 }
337 
338 
339 template<class T>
341 (
342  const const_iterator& iter
343 ) const
344 {
345  return ptr_ != iter.ptr_;
346 }
347 
348 
349 template<class T>
351 {
352  return **ptr_;
353 }
354 
355 
356 template<class T>
358 {
359  return operator*();
360 }
361 
362 
363 template<class T>
364 inline typename Foam::UPtrList<T>::const_iterator
366 {
367  ++ptr_;
368  return *this;
369 }
370 
371 
372 template<class T>
373 inline typename Foam::UPtrList<T>::const_iterator
375 {
376  const_iterator tmp = *this;
377  ++ptr_;
378  return tmp;
379 }
380 
381 
382 template<class T>
383 inline typename Foam::UPtrList<T>::const_iterator
385 {
386  --ptr_;
387  return *this;
388 }
389 
390 
391 template<class T>
392 inline typename Foam::UPtrList<T>::const_iterator
394 {
395  const_iterator tmp = *this;
396  --ptr_;
397  return tmp;
398 }
399 
400 
401 template<class T>
402 inline typename Foam::UPtrList<T>::const_iterator
404 {
405  ptr_ += n;
406  return *this;
407 }
408 
409 
410 template<class T>
411 inline typename Foam::UPtrList<T>::const_iterator
413 {
414  ptr_ -= n;
415  return *this;
416 }
417 
418 
419 template<class T>
420 inline typename Foam::UPtrList<T>::const_iterator
422 {
423  typename UPtrList<T>::const_iterator tmp = *this;
424  return tmp += n;
425 }
426 
427 
428 template<class T>
429 inline typename Foam::UPtrList<T>::const_iterator
431 {
432  typename UPtrList<T>::const_iterator tmp = *this;
433  return tmp -= n;
434 }
435 
436 
437 template<class T>
439 (
440  const typename UPtrList<T>::const_iterator& iter
441 ) const
442 {
443  return (ptr_ - iter.ptr_);
444 }
445 
446 
447 template<class T>
449 {
450  return *(*this + n);
451 }
452 
453 
454 template<class T>
456 (
457  const const_iterator& iter
458 ) const
459 {
460  return ptr_ < iter.ptr_;
461 }
462 
463 
464 template<class T>
466 (
467  const const_iterator& iter
468 ) const
469 {
470  return ptr_ > iter.ptr_;
471 }
472 
473 
474 template<class T>
476 (
477  const const_iterator& iter
478 ) const
479 {
480  return ptr_ <= iter.ptr_;
481 }
482 
483 
484 template<class T>
486 (
487  const const_iterator& iter
488 ) const
489 {
490  return ptr_ >= iter.ptr_;
491 }
492 
493 
494 template<class T>
495 inline typename Foam::UPtrList<T>::const_iterator
497 {
498  return ptrs_.begin();
499 }
500 
501 
502 template<class T>
503 inline typename Foam::UPtrList<T>::const_iterator
505 {
506  return ptrs_.end();
507 }
508 
509 
510 template<class T>
511 inline typename Foam::UPtrList<T>::const_iterator
513 {
514  return ptrs_.begin();
515 }
516 
517 
518 template<class T>
519 inline typename Foam::UPtrList<T>::const_iterator
521 {
522  return ptrs_.end();
523 }
524 
525 
526 // ************************************************************************* //
label n
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
iterator end()
Return an iterator to end traversing the UList.
Definition: UListI.H:224
An STL-conforming const_iterator.
Definition: UPtrList.H:253
const_iterator operator-(const label) const
Definition: UPtrListI.H:430
const T & operator[](const label)
Definition: UPtrListI.H:448
const_iterator operator--()
Definition: UPtrListI.H:384
const_iterator operator+=(const label)
Definition: UPtrListI.H:403
const_iterator(const T *const *)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:316
const_iterator operator+(const label) const
Definition: UPtrListI.H:421
const_iterator operator-=(const label)
Definition: UPtrListI.H:412
const_iterator operator++()
Definition: UPtrListI.H:365
An STL iterator.
Definition: UPtrList.H:200
bool operator!=(const iterator &) const
Definition: UPtrListI.H:158
bool operator>(const iterator &) const
Definition: UPtrListI.H:277
iterator operator-(const label) const
Definition: UPtrListI.H:245
T & operator[](const label)
Definition: UPtrListI.H:263
bool operator==(const iterator &) const
Definition: UPtrListI.H:151
bool operator<(const iterator &) const
Definition: UPtrListI.H:270
iterator operator+(const label) const
Definition: UPtrListI.H:236
iterator operator-=(const label)
Definition: UPtrListI.H:227
bool operator<=(const iterator &) const
Definition: UPtrListI.H:284
bool operator>=(const iterator &) const
Definition: UPtrListI.H:291
iterator operator+=(const label)
Definition: UPtrListI.H:218
iterator(T **)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:144
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
iterator begin()
Return an iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:299
T & first()
Return reference to the first element of the list.
Definition: UPtrListI.H:43
bool set(const label) const
Is element set.
Definition: UPtrListI.H:78
iterator end()
Return an iterator to end traversing the UPtrList.
Definition: UPtrListI.H:307
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void resize(const label)
Reset size of UPtrList. This can only be used to set the size.
Definition: UPtrListI.H:71
bool empty() const
Return true if the UPtrList is empty (ie, size() is zero)
Definition: UPtrListI.H:36
friend class iterator
Definition: UPtrList.H:195
const T & operator[](const label) const
Return element const reference.
Definition: UPtrListI.H:96
const_iterator cbegin() const
Return an const_iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:512
const_iterator cend() const
Return an const_iterator to end traversing the UPtrList.
Definition: UPtrListI.H:520
const T * operator()(const label) const
Return element const pointer.
Definition: UPtrListI.H:128
T & last()
Return reference to the last element of the list.
Definition: UPtrListI.H:57
A class for managing temporary objects.
Definition: tmp.H:55
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
error FatalError
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
points setSize(newPointi)