UPtrListI.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-2016 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 template<class T>
95 {
96  return xferMove(*this);
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
101 
102 template<class T>
103 inline const T& Foam::UPtrList<T>::operator[](const label i) const
104 {
105  if (!ptrs_[i])
106  {
108  << "hanging pointer at index " << i
109  << " (size " << size()
110  << "), cannot dereference"
111  << abort(FatalError);
112  }
113 
114  return *(ptrs_[i]);
115 }
116 
117 
118 template<class T>
120 {
121  if (!ptrs_[i])
122  {
124  << "hanging pointer at index " << i
125  << " (size " << size()
126  << "), cannot dereference"
127  << abort(FatalError);
128  }
129 
130  return *(ptrs_[i]);
131 }
132 
133 
134 template<class T>
135 inline const T* Foam::UPtrList<T>::operator()(const label i) const
136 {
137  return ptrs_[i];
138 }
139 
140 
141 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
142 
143 template<class T>
145 :
146  ptr_(ptr)
147 {}
148 
149 template<class T>
150 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
151 {
152  return ptr_ == iter.ptr_;
153 }
154 
155 template<class T>
156 inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
157 {
158  return ptr_ != iter.ptr_;
159 }
160 
161 template<class T>
163 {
164  return **ptr_;
165 }
166 
167 template<class T>
169 {
170  return operator*();
171 }
172 
173 template<class T>
174 inline typename Foam::UPtrList<T>::iterator
176 {
177  ++ptr_;
178  return *this;
179 }
180 
181 template<class T>
182 inline typename Foam::UPtrList<T>::iterator
184 {
185  iterator tmp = *this;
186  ++ptr_;
187  return tmp;
188 }
189 
190 template<class T>
191 inline typename Foam::UPtrList<T>::iterator
193 {
194  --ptr_;
195  return *this;
196 }
197 
198 template<class T>
199 inline typename Foam::UPtrList<T>::iterator
201 {
202  iterator tmp = *this;
203  --ptr_;
204  return tmp;
205 }
206 
207 template<class T>
208 inline typename Foam::UPtrList<T>::iterator
210 {
211  ptr_ += n;
212  return *this;
213 }
214 
215 template<class T>
216 inline typename Foam::UPtrList<T>::iterator
217 Foam::operator+(const typename UPtrList<T>::iterator& iter, label n)
218 {
219  typename UPtrList<T>::iterator tmp = iter;
220  return tmp += n;
221 }
222 
223 template<class T>
224 inline typename Foam::UPtrList<T>::iterator
225 Foam::operator+(label n, const typename UPtrList<T>::iterator& iter)
226 {
227  typename UPtrList<T>::iterator tmp = iter;
228  return tmp += n;
229 }
230 
231 template<class T>
232 inline typename Foam::UPtrList<T>::iterator
234 {
235  ptr_ -= n;
236  return *this;
237 }
238 
239 template<class T>
240 inline typename Foam::UPtrList<T>::iterator
241 Foam::operator-(const typename UPtrList<T>::iterator& iter, label n)
242 {
243  typename UPtrList<T>::iterator tmp = iter;
244  return tmp -= n;
245 }
246 
247 template<class T>
248 inline Foam::label Foam::operator-
249 (
250  const typename UPtrList<T>::iterator& iter1,
251  const typename UPtrList<T>::iterator& iter2
252 )
253 {
254  return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
255 }
256 
257 template<class T>
259 {
260  return *(*this + n);
261 }
262 
263 template<class T>
264 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
265 {
266  return ptr_ < iter.ptr_;
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 template<class T>
276 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
277 {
278  return ptr_ <= iter.ptr_;
279 }
280 
281 template<class T>
282 inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
283 {
284  return ptr_ >= iter.ptr_;
285 }
286 
287 template<class T>
288 inline typename Foam::UPtrList<T>::iterator
290 {
291  return ptrs_.begin();
292 }
293 
294 template<class T>
295 inline typename Foam::UPtrList<T>::iterator
297 {
298  return ptrs_.end();
299 }
300 
301 
302 // * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
303 
304 template<class T>
306 :
307  ptr_(ptr)
308 {}
309 
310 
311 template<class T>
313 :
314  ptr_(iter.ptr_)
315 {}
316 
317 
318 template<class T>
320 (
321  const const_iterator& iter
322 ) const
323 {
324  return ptr_ == iter.ptr_;
325 }
326 
327 
328 template<class T>
330 (
331  const const_iterator& iter
332 ) const
333 {
334  return ptr_ != iter.ptr_;
335 }
336 
337 
338 template<class T>
340 {
341  return **ptr_;
342 }
343 
344 
345 template<class T>
347 {
348  return operator*();
349 }
350 
351 
352 template<class T>
353 inline typename Foam::UPtrList<T>::const_iterator
355 {
356  ++ptr_;
357  return *this;
358 }
359 
360 
361 template<class T>
362 inline typename Foam::UPtrList<T>::const_iterator
364 {
365  const_iterator tmp = *this;
366  ++ptr_;
367  return tmp;
368 }
369 
370 
371 template<class T>
372 inline typename Foam::UPtrList<T>::const_iterator
374 {
375  --ptr_;
376  return *this;
377 }
378 
379 
380 template<class T>
381 inline typename Foam::UPtrList<T>::const_iterator
383 {
384  const_iterator tmp = *this;
385  --ptr_;
386  return tmp;
387 }
388 
389 
390 template<class T>
391 inline typename Foam::UPtrList<T>::const_iterator
393 {
394  ptr_ += n;
395  return *this;
396 }
397 
398 
399 template<class T>
400 inline typename Foam::UPtrList<T>::const_iterator
401 Foam::operator+(const typename UPtrList<T>::const_iterator& iter, label n)
402 {
403  typename UPtrList<T>::const_iterator tmp = iter;
404  return tmp += n;
405 }
406 
407 
408 template<class T>
409 inline typename Foam::UPtrList<T>::const_iterator
410 Foam::operator+(label n, const typename UPtrList<T>::const_iterator& iter)
411 {
412  typename UPtrList<T>::const_iterator tmp = iter;
413  return tmp += n;
414 }
415 
416 
417 template<class T>
418 inline typename Foam::UPtrList<T>::const_iterator
420 {
421  ptr_ -= n;
422  return *this;
423 }
424 
425 
426 template<class T>
427 inline typename Foam::UPtrList<T>::const_iterator
428 Foam::operator-(const typename UPtrList<T>::const_iterator& iter, label n)
429 {
430  typename UPtrList<T>::const_iterator tmp = iter;
431  return tmp -= n;
432 }
433 
434 
435 template<class T>
436 inline Foam::label Foam::operator-
437 (
438  const typename UPtrList<T>::const_iterator& iter1,
439  const typename UPtrList<T>::const_iterator& iter2
440 )
441 {
442  return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
443 }
444 
445 
446 template<class T>
448 {
449  return *(*this + n);
450 }
451 
452 
453 template<class T>
455 (
456  const const_iterator& iter
457 ) const
458 {
459  return ptr_ < iter.ptr_;
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>
494 inline typename Foam::UPtrList<T>::const_iterator
496 {
497  return ptrs_.begin();
498 }
499 
500 
501 template<class T>
502 inline typename Foam::UPtrList<T>::const_iterator
504 {
505  return ptrs_.end();
506 }
507 
508 
509 template<class T>
510 inline typename Foam::UPtrList<T>::const_iterator
512 {
513  return ptrs_.begin();
514 }
515 
516 
517 template<class T>
518 inline typename Foam::UPtrList<T>::const_iterator
520 {
521  return ptrs_.end();
522 }
523 
524 
525 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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
Xfer< UPtrList< T > > xfer()
Transfer contents to the Xfer container.
Definition: UPtrListI.H:94
iterator(T **)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:144
const_iterator operator+=(label)
Definition: UPtrListI.H:392
error FatalError
const_iterator(const T *const *)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:305
#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:103
bool empty() const
Return true if the UPtrList is empty (ie, size() is zero)
Definition: UPtrListI.H:36
iterator operator+=(label)
Definition: UPtrListI.H:209
iterator end()
Return an iterator to end traversing the UPtrList.
Definition: UPtrListI.H:296
iterator operator-=(label)
Definition: UPtrListI.H:233
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:302
An STL iterator.
Definition: UPtrList.H:244
const T & operator[](label)
Definition: UPtrListI.H:447
points setSize(newPointi)
bool operator<(const iterator &) const
Definition: UPtrListI.H:264
bool operator<=(const iterator &) const
Definition: UPtrListI.H:276
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
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
const_iterator operator-=(label)
Definition: UPtrListI.H:419
bool operator>=(const iterator &) const
Definition: UPtrListI.H:282
bool set(const label) const
Is element set.
Definition: UPtrListI.H:78
bool operator==(const iterator &) const
Definition: UPtrListI.H:150
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
iterator begin()
Return an iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:289
const_iterator operator--()
Definition: UPtrListI.H:373
label n
const_iterator operator++()
Definition: UPtrListI.H:354
bool operator!=(const iterator &) const
Definition: UPtrListI.H:156
const_iterator cend() const
Return an const_iterator to end traversing the UPtrList.
Definition: UPtrListI.H:519
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:511
const T * operator()(const label) const
Return element const pointer.
Definition: UPtrListI.H:135
T & first()
Return reference to the first element of the list.
Definition: UPtrListI.H:43