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 void Foam::UPtrList<T>::append(T* ptr)
79 {
80  label sz = this->size();
81  this->setSize(sz+1);
82  this->ptrs_[sz] = ptr;
83 }
84 
85 
86 template<class T>
87 inline bool Foam::UPtrList<T>::set(const label i) const
88 {
89  return ptrs_[i] != nullptr;
90 }
91 
92 
93 template<class T>
94 inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
95 {
96  T* old = ptrs_[i];
97  ptrs_[i] = ptr;
98  return old;
99 }
100 
101 
102 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
103 
104 template<class T>
105 inline const T& Foam::UPtrList<T>::operator[](const label i) const
106 {
107  if (!ptrs_[i])
108  {
110  << "hanging pointer at index " << i
111  << " (size " << size()
112  << "), cannot dereference"
113  << abort(FatalError);
114  }
115 
116  return *(ptrs_[i]);
117 }
118 
119 
120 template<class T>
122 {
123  if (!ptrs_[i])
124  {
126  << "hanging pointer at index " << i
127  << " (size " << size()
128  << "), cannot dereference"
129  << abort(FatalError);
130  }
131 
132  return *(ptrs_[i]);
133 }
134 
135 
136 template<class T>
137 inline const T* Foam::UPtrList<T>::operator()(const label i) const
138 {
139  return ptrs_[i];
140 }
141 
142 
143 template<class T>
145 {
146  return ptrs_[i];
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
151 
152 template<class T>
154 :
155  ptr_(ptr)
156 {}
157 
158 
159 template<class T>
160 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
161 {
162  return ptr_ == iter.ptr_;
163 }
164 
165 
166 template<class T>
167 inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
168 {
169  return ptr_ != iter.ptr_;
170 }
171 
172 
173 template<class T>
175 {
176  return **ptr_;
177 }
178 
179 
180 template<class T>
182 {
183  return operator*();
184 }
185 
186 
187 template<class T>
188 inline typename Foam::UPtrList<T>::iterator
190 {
191  ++ptr_;
192  return *this;
193 }
194 
195 
196 template<class T>
197 inline typename Foam::UPtrList<T>::iterator
199 {
200  iterator tmp = *this;
201  ++ptr_;
202  return tmp;
203 }
204 
205 
206 template<class T>
207 inline typename Foam::UPtrList<T>::iterator
209 {
210  --ptr_;
211  return *this;
212 }
213 
214 
215 template<class T>
218 {
219  iterator tmp = *this;
220  --ptr_;
221  return tmp;
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  ptr_ -= n;
239  return *this;
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>
253 inline typename Foam::UPtrList<T>::iterator
255 {
256  typename UPtrList<T>::iterator tmp = *this;
257  return tmp -= n;
258 }
259 
260 
261 template<class T>
263 (
264  const typename UPtrList<T>::iterator& iter
265 ) const
266 {
267  return (ptr_ - iter.ptr_);
268 }
269 
270 
271 template<class T>
273 {
274  return *(*this + n);
275 }
276 
277 
278 template<class T>
279 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
280 {
281  return ptr_ < iter.ptr_;
282 }
283 
284 
285 template<class T>
286 inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
287 {
288  return ptr_ > iter.ptr_;
289 }
290 
291 
292 template<class T>
293 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
294 {
295  return ptr_ <= iter.ptr_;
296 }
297 
298 
299 template<class T>
300 inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
301 {
302  return ptr_ >= iter.ptr_;
303 }
304 
305 
306 template<class T>
309 {
310  return ptrs_.begin();
311 }
312 
313 
314 template<class T>
315 inline typename Foam::UPtrList<T>::iterator
317 {
318  return ptrs_.end();
319 }
320 
321 
322 // * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
323 
324 template<class T>
326 :
327  ptr_(ptr)
328 {}
329 
330 
331 template<class T>
333 :
334  ptr_(iter.ptr_)
335 {}
336 
337 
338 template<class T>
340 (
341  const const_iterator& iter
342 ) const
343 {
344  return ptr_ == iter.ptr_;
345 }
346 
347 
348 template<class T>
350 (
351  const const_iterator& iter
352 ) const
353 {
354  return ptr_ != iter.ptr_;
355 }
356 
357 
358 template<class T>
360 {
361  return **ptr_;
362 }
363 
364 
365 template<class T>
367 {
368  return operator*();
369 }
370 
371 
372 template<class T>
373 inline typename Foam::UPtrList<T>::const_iterator
375 {
376  ++ptr_;
377  return *this;
378 }
379 
380 
381 template<class T>
382 inline typename Foam::UPtrList<T>::const_iterator
384 {
385  const_iterator tmp = *this;
386  ++ptr_;
387  return tmp;
388 }
389 
390 
391 template<class T>
392 inline typename Foam::UPtrList<T>::const_iterator
394 {
395  --ptr_;
396  return *this;
397 }
398 
399 
400 template<class T>
401 inline typename Foam::UPtrList<T>::const_iterator
403 {
404  const_iterator tmp = *this;
405  --ptr_;
406  return tmp;
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  ptr_ -= n;
424  return *this;
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>
438 inline typename Foam::UPtrList<T>::const_iterator
440 {
441  typename UPtrList<T>::const_iterator tmp = *this;
442  return tmp -= n;
443 }
444 
445 
446 template<class T>
448 (
449  const typename UPtrList<T>::const_iterator& iter
450 ) const
451 {
452  return (ptr_ - iter.ptr_);
453 }
454 
455 
456 template<class T>
458 {
459  return *(*this + n);
460 }
461 
462 
463 template<class T>
465 (
466  const const_iterator& iter
467 ) const
468 {
469  return ptr_ < iter.ptr_;
470 }
471 
472 
473 template<class T>
475 (
476  const const_iterator& iter
477 ) const
478 {
479  return ptr_ > iter.ptr_;
480 }
481 
482 
483 template<class T>
485 (
486  const const_iterator& iter
487 ) const
488 {
489  return ptr_ <= iter.ptr_;
490 }
491 
492 
493 template<class T>
495 (
496  const const_iterator& iter
497 ) const
498 {
499  return ptr_ >= iter.ptr_;
500 }
501 
502 
503 template<class T>
504 inline typename Foam::UPtrList<T>::const_iterator
506 {
507  return ptrs_.begin();
508 }
509 
510 
511 template<class T>
512 inline typename Foam::UPtrList<T>::const_iterator
514 {
515  return ptrs_.end();
516 }
517 
518 
519 template<class T>
520 inline typename Foam::UPtrList<T>::const_iterator
522 {
523  return ptrs_.begin();
524 }
525 
526 
527 template<class T>
528 inline typename Foam::UPtrList<T>::const_iterator
530 {
531  return ptrs_.end();
532 }
533 
534 
535 // ************************************************************************* //
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:256
const_iterator operator-(const label) const
Definition: UPtrListI.H:439
const T & operator[](const label)
Definition: UPtrListI.H:457
const_iterator operator--()
Definition: UPtrListI.H:393
const_iterator operator+=(const label)
Definition: UPtrListI.H:412
const_iterator(const T *const *)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:325
const_iterator operator+(const label) const
Definition: UPtrListI.H:430
const_iterator operator-=(const label)
Definition: UPtrListI.H:421
const_iterator operator++()
Definition: UPtrListI.H:374
An STL iterator.
Definition: UPtrList.H:203
bool operator!=(const iterator &) const
Definition: UPtrListI.H:167
bool operator>(const iterator &) const
Definition: UPtrListI.H:286
iterator operator-(const label) const
Definition: UPtrListI.H:254
T & operator[](const label)
Definition: UPtrListI.H:272
bool operator==(const iterator &) const
Definition: UPtrListI.H:160
bool operator<(const iterator &) const
Definition: UPtrListI.H:279
iterator operator+(const label) const
Definition: UPtrListI.H:245
iterator operator-=(const label)
Definition: UPtrListI.H:236
bool operator<=(const iterator &) const
Definition: UPtrListI.H:293
bool operator>=(const iterator &) const
Definition: UPtrListI.H:300
iterator operator+=(const label)
Definition: UPtrListI.H:227
iterator(T **)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:153
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:308
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:87
iterator end()
Return an iterator to end traversing the UPtrList.
Definition: UPtrListI.H:316
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:198
const T & operator[](const label) const
Return element const reference.
Definition: UPtrListI.H:105
const_iterator cbegin() const
Return an const_iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:521
const_iterator cend() const
Return an const_iterator to end traversing the UPtrList.
Definition: UPtrListI.H:529
void append(T *)
Append an element at the end of the list.
Definition: UPtrListI.H:78
const T * operator()(const label) const
Return element const pointer.
Definition: UPtrListI.H:137
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:334
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)