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-2013 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 #include "error.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class T>
32 {
33  return ptrs_.size();
34 }
35 
36 
37 template<class T>
38 inline bool Foam::UPtrList<T>::empty() const
39 {
40  return ptrs_.empty();
41 }
42 
43 
44 template<class T>
46 {
47  return this->operator[](0);
48 }
49 
50 
51 template<class T>
52 inline const T& Foam::UPtrList<T>::first() const
53 {
54  return this->operator[](0);
55 }
56 
57 
58 template<class T>
60 {
61  return this->operator[](this->size()-1);
62 }
63 
64 
65 template<class T>
66 inline const T& Foam::UPtrList<T>::last() const
67 {
68  return this->operator[](this->size()-1);
69 }
70 
71 
72 template<class T>
73 inline void Foam::UPtrList<T>::resize(const label newSize)
74 {
75  this->setSize(newSize);
76 }
77 
78 
79 template<class T>
80 inline bool Foam::UPtrList<T>::set(const label i) const
81 {
82  return ptrs_[i] != NULL;
83 }
84 
85 
86 template<class T>
87 inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
88 {
89  T* old = ptrs_[i];
90  ptrs_[i] = ptr;
91  return old;
92 }
93 
94 
95 template<class T>
97 {
98  return xferMove(*this);
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  {
109  FatalErrorIn("UPtrList::operator[] const")
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  {
125  FatalErrorIn("UPtrList::operator[]")
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 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
144 
145 template<class T>
147 :
148  ptr_(ptr)
149 {}
150 
151 template<class T>
152 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
153 {
154  return ptr_ == iter.ptr_;
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 template<class T>
165 {
166  return **ptr_;
167 }
168 
169 template<class T>
171 {
172  return operator*();
173 }
174 
175 template<class T>
176 inline typename Foam::UPtrList<T>::iterator
178 {
179  ++ptr_;
180  return *this;
181 }
182 
183 template<class T>
184 inline typename Foam::UPtrList<T>::iterator
186 {
187  iterator tmp = *this;
188  ++ptr_;
189  return tmp;
190 }
191 
192 template<class T>
193 inline typename Foam::UPtrList<T>::iterator
195 {
196  --ptr_;
197  return *this;
198 }
199 
200 template<class T>
201 inline typename Foam::UPtrList<T>::iterator
203 {
204  iterator tmp = *this;
205  --ptr_;
206  return tmp;
207 }
208 
209 template<class T>
210 inline typename Foam::UPtrList<T>::iterator
212 {
213  ptr_ += n;
214  return *this;
215 }
216 
217 template<class T>
218 inline typename Foam::UPtrList<T>::iterator
219 Foam::operator+(const typename UPtrList<T>::iterator& iter, label n)
220 {
221  typename UPtrList<T>::iterator tmp = iter;
222  return tmp += n;
223 }
224 
225 template<class T>
226 inline typename Foam::UPtrList<T>::iterator
227 Foam::operator+(label n, const typename UPtrList<T>::iterator& iter)
228 {
229  typename UPtrList<T>::iterator tmp = iter;
230  return tmp += n;
231 }
232 
233 template<class T>
234 inline typename Foam::UPtrList<T>::iterator
236 {
237  ptr_ -= n;
238  return *this;
239 }
240 
241 template<class T>
242 inline typename Foam::UPtrList<T>::iterator
243 Foam::operator-(const typename UPtrList<T>::iterator& iter, label n)
244 {
245  typename UPtrList<T>::iterator tmp = iter;
246  return tmp -= n;
247 }
248 
249 template<class T>
250 inline Foam::label Foam::operator-
251 (
252  const typename UPtrList<T>::iterator& iter1,
253  const typename UPtrList<T>::iterator& iter2
254 )
255 {
256  return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
257 }
258 
259 template<class T>
261 {
262  return *(*this + n);
263 }
264 
265 template<class T>
266 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
267 {
268  return ptr_ < iter.ptr_;
269 }
270 
271 template<class T>
272 inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
273 {
274  return ptr_ > iter.ptr_;
275 }
276 
277 template<class T>
278 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
279 {
280  return ptr_ <= iter.ptr_;
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 template<class T>
290 inline typename Foam::UPtrList<T>::iterator
292 {
293  return ptrs_.begin();
294 }
295 
296 template<class T>
297 inline typename Foam::UPtrList<T>::iterator
299 {
300  return ptrs_.end();
301 }
302 
303 
304 // ************************************************************************* //
An STL iterator.
Definition: UPtrList.H:208
const T & operator[](const label) const
Return element const reference.
Definition: UPtrListI.H:105
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
iterator end()
Return an iterator to end traversing the UPtrList.
Definition: UPtrListI.H:298
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
bool empty() const
Return true if the UPtrList is empty (ie, size() is zero).
Definition: UPtrListI.H:38
Xfer< UPtrList< T > > xfer()
Transfer contents to the Xfer container.
Definition: UPtrListI.H:96
Xfer< T > xferMove(T &)
void resize(const label)
Reset size of UPtrList. This can only be used to set the size.
Definition: UPtrListI.H:73
iterator operator+=(label)
Definition: UPtrListI.H:211
const volScalarField & T
Definition: createFields.H:25
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
label n
const T * operator()(const label) const
Return element const pointer.
Definition: UPtrListI.H:137
iterator begin()
Return an iterator to begin traversing the UPtrList.
Definition: UPtrListI.H:291
iterator operator-=(label)
Definition: UPtrListI.H:235
bool operator<(const iterator &) const
Definition: UPtrListI.H:266
bool operator>(const iterator &) const
Definition: UPtrListI.H:272
errorManip< error > abort(error &err)
Definition: errorManip.H:131
T & first()
Return reference to the first element of the list.
Definition: UPtrListI.H:45
bool set(const label) const
Is element set.
Definition: UPtrListI.H:80
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
bool operator<=(const iterator &) const
Definition: UPtrListI.H:278
points setSize(newPointi)
bool operator!=(const iterator &) const
Definition: UPtrListI.H:158
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:31
error FatalError
T & last()
Return reference to the last element of the list.
Definition: UPtrListI.H:59
iterator(T **)
Construct for a given UPtrList entry.
Definition: UPtrListI.H:146
A class for managing temporary objects.
Definition: PtrList.H:118
bool operator==(const iterator &) const
Definition: UPtrListI.H:152
bool operator>=(const iterator &) const
Definition: UPtrListI.H:284