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-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 // * * * * * * * * * * * * * * * 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 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
135 
136 template<class T>
138 :
139  ptr_(ptr)
140 {}
141 
142 
143 template<class T>
144 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
145 {
146  return ptr_ == iter.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>
159 {
160  return **ptr_;
161 }
162 
163 
164 template<class T>
166 {
167  return operator*();
168 }
169 
170 
171 template<class T>
172 inline typename Foam::UPtrList<T>::iterator
174 {
175  ++ptr_;
176  return *this;
177 }
178 
179 
180 template<class T>
181 inline typename Foam::UPtrList<T>::iterator
183 {
184  iterator tmp = *this;
185  ++ptr_;
186  return tmp;
187 }
188 
189 
190 template<class T>
191 inline typename Foam::UPtrList<T>::iterator
193 {
194  --ptr_;
195  return *this;
196 }
197 
198 
199 template<class T>
200 inline typename Foam::UPtrList<T>::iterator
202 {
203  iterator tmp = *this;
204  --ptr_;
205  return tmp;
206 }
207 
208 
209 template<class T>
210 inline typename Foam::UPtrList<T>::iterator
212 {
213  ptr_ += n;
214  return *this;
215 }
216 
217 
218 template<class T>
219 inline typename Foam::UPtrList<T>::iterator
221 {
222  ptr_ -= n;
223  return *this;
224 }
225 
226 
227 template<class T>
228 inline typename Foam::UPtrList<T>::iterator
230 {
231  typename UPtrList<T>::iterator tmp = *this;
232  return tmp += n;
233 }
234 
235 
236 template<class T>
237 inline typename Foam::UPtrList<T>::iterator
239 {
240  typename UPtrList<T>::iterator tmp = *this;
241  return tmp -= n;
242 }
243 
244 
245 template<class T>
247 (
248  const typename UPtrList<T>::iterator& iter
249 ) const
250 {
251  return (ptr_ - iter.ptr_);
252 }
253 
254 
255 template<class T>
257 {
258  return *(*this + n);
259 }
260 
261 
262 template<class T>
263 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
264 {
265  return ptr_ < iter.ptr_;
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 typename Foam::UPtrList<T>::iterator
293 {
294  return ptrs_.begin();
295 }
296 
297 
298 template<class T>
299 inline typename Foam::UPtrList<T>::iterator
301 {
302  return ptrs_.end();
303 }
304 
305 
306 // * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
307 
308 template<class T>
310 :
311  ptr_(ptr)
312 {}
313 
314 
315 template<class T>
317 :
318  ptr_(iter.ptr_)
319 {}
320 
321 
322 template<class T>
324 (
325  const const_iterator& iter
326 ) const
327 {
328  return ptr_ == iter.ptr_;
329 }
330 
331 
332 template<class T>
334 (
335  const const_iterator& iter
336 ) const
337 {
338  return ptr_ != iter.ptr_;
339 }
340 
341 
342 template<class T>
344 {
345  return **ptr_;
346 }
347 
348 
349 template<class T>
351 {
352  return operator*();
353 }
354 
355 
356 template<class T>
357 inline typename Foam::UPtrList<T>::const_iterator
359 {
360  ++ptr_;
361  return *this;
362 }
363 
364 
365 template<class T>
366 inline typename Foam::UPtrList<T>::const_iterator
368 {
369  const_iterator tmp = *this;
370  ++ptr_;
371  return tmp;
372 }
373 
374 
375 template<class T>
376 inline typename Foam::UPtrList<T>::const_iterator
378 {
379  --ptr_;
380  return *this;
381 }
382 
383 
384 template<class T>
385 inline typename Foam::UPtrList<T>::const_iterator
387 {
388  const_iterator tmp = *this;
389  --ptr_;
390  return tmp;
391 }
392 
393 
394 template<class T>
395 inline typename Foam::UPtrList<T>::const_iterator
397 {
398  ptr_ += n;
399  return *this;
400 }
401 
402 
403 template<class T>
404 inline typename Foam::UPtrList<T>::const_iterator
406 {
407  ptr_ -= n;
408  return *this;
409 }
410 
411 
412 template<class T>
413 inline typename Foam::UPtrList<T>::const_iterator
415 {
416  typename UPtrList<T>::const_iterator tmp = *this;
417  return tmp += n;
418 }
419 
420 
421 template<class T>
422 inline typename Foam::UPtrList<T>::const_iterator
424 {
425  typename UPtrList<T>::const_iterator tmp = *this;
426  return tmp -= n;
427 }
428 
429 
430 template<class T>
432 (
433  const typename UPtrList<T>::const_iterator& iter
434 ) const
435 {
436  return (ptr_ - iter.ptr_);
437 }
438 
439 
440 template<class T>
442 {
443  return *(*this + n);
444 }
445 
446 
447 template<class T>
449 (
450  const const_iterator& iter
451 ) const
452 {
453  return ptr_ < iter.ptr_;
454 }
455 
456 
457 template<class T>
459 (
460  const const_iterator& iter
461 ) const
462 {
463  return ptr_ > iter.ptr_;
464 }
465 
466 
467 template<class T>
469 (
470  const const_iterator& iter
471 ) const
472 {
473  return ptr_ <= iter.ptr_;
474 }
475 
476 
477 template<class T>
479 (
480  const const_iterator& iter
481 ) const
482 {
483  return ptr_ >= iter.ptr_;
484 }
485 
486 
487 template<class T>
488 inline typename Foam::UPtrList<T>::const_iterator
490 {
491  return ptrs_.begin();
492 }
493 
494 
495 template<class T>
496 inline typename Foam::UPtrList<T>::const_iterator
498 {
499  return ptrs_.end();
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 // ************************************************************************* //
iterator operator-=(const label)
Definition: UPtrListI.H:220
void resize(const label)
Reset size of UPtrList. This can only be used to set the size.
Definition: UPtrListI.H:71
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
iterator(T **)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:137
iterator operator-(const label) const
Definition: UPtrListI.H:238
T & operator[](const label)
Definition: UPtrListI.H:256
error FatalError
const_iterator(const T *const *)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:309
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const T & operator[](const label) const
Return element const reference.
Definition: UPtrListI.H:96
bool empty() const
Return true if the UPtrList is empty (ie, size() is zero)
Definition: UPtrListI.H:36
iterator end()
Return an iterator to end traversing the UPtrList.
Definition: UPtrListI.H:300
bool operator>(const iterator &) const
Definition: UPtrListI.H:270
T & last()
Return reference to the last element of the list.
Definition: UPtrListI.H:57
An STL-conforming const_iterator.
Definition: UPtrList.H:238
const_iterator operator+(const label) const
Definition: UPtrListI.H:414
An STL iterator.
Definition: UPtrList.H:185
points setSize(newPointi)
bool operator<(const iterator &) const
Definition: UPtrListI.H:263
bool operator<=(const iterator &) const
Definition: UPtrListI.H:277
iterator operator+=(const label)
Definition: UPtrListI.H:211
iterator operator+(const label) const
Definition: UPtrListI.H:229
const_iterator operator+=(const label)
Definition: UPtrListI.H:396
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool operator>=(const iterator &) const
Definition: UPtrListI.H:284
bool set(const label) const
Is element set.
Definition: UPtrListI.H:78
bool operator==(const iterator &) const
Definition: UPtrListI.H:144
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const volScalarField & T
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
const_iterator operator-(const label) const
Definition: UPtrListI.H:423
iterator begin()
Return an iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:292
const_iterator operator--()
Definition: UPtrListI.H:377
label n
const T & operator[](const label)
Definition: UPtrListI.H:441
const_iterator operator++()
Definition: UPtrListI.H:358
bool operator!=(const iterator &) const
Definition: UPtrListI.H:151
const_iterator cend() const
Return an const_iterator to end traversing the UPtrList.
Definition: UPtrListI.H:513
A class for managing temporary objects.
Definition: PtrList.H:53
const_iterator cbegin() const
Return an const_iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:505
const T * operator()(const label) const
Return element const pointer.
Definition: UPtrListI.H:128
const_iterator operator-=(const label)
Definition: UPtrListI.H:405
T & first()
Return reference to the first element of the list.
Definition: UPtrListI.H:43