FreeFOAM The Cross-Platform CFD Toolkit
PtrListI.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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/error.H>
27 
28 #include <OpenFOAM/autoPtr.H>
29 #include <OpenFOAM/tmp.H>
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<class T>
34 inline Foam::label Foam::PtrList<T>::size() const
35 {
36  return ptrs_.size();
37 }
38 
39 
40 template<class T>
41 inline bool Foam::PtrList<T>::empty() const
42 {
43  return ptrs_.empty();
44 }
45 
46 
47 template<class T>
48 inline void Foam::PtrList<T>::resize(const label newSize)
49 {
50  this->setSize(newSize);
51 }
52 
53 
54 template<class T>
55 inline bool Foam::PtrList<T>::set(const label i) const
56 {
57  return ptrs_[i] != NULL;
58 }
59 
60 
61 template<class T>
62 inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
63 {
64  autoPtr<T> old(ptrs_[i]);
65 
66  ptrs_[i] = ptr;
67 
68  return old;
69 }
70 
71 
72 template<class T>
74 (
75  const label i,
76  const autoPtr<T>& aptr
77 )
78 {
79  return set(i, const_cast<autoPtr<T>&>(aptr).ptr());
80 }
81 
82 
83 template<class T>
85 (
86  const label i,
87  const tmp<T>& t
88 )
89 {
90  return set(i, const_cast<tmp<T>&>(t).ptr());
91 }
92 
93 
94 template<class T>
96 {
97  return xferMove(*this);
98 }
99 
100 
101 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
102 
103 template<class T>
104 const T& Foam::PtrList<T>::operator[](const label i) const
105 {
106  if (!ptrs_[i])
107  {
108  FatalErrorIn("PtrList::operator[] const")
109  << "hanging pointer, cannot dereference"
110  << abort(FatalError);
111  }
112 
113  return *(ptrs_[i]);
114 }
115 
116 
117 template<class T>
119 {
120  if (!ptrs_[i])
121  {
122  FatalErrorIn("PtrList::operator[]")
123  << "hanging pointer, cannot dereference"
124  << abort(FatalError);
125  }
126 
127  return *(ptrs_[i]);
128 }
129 
130 
131 template<class T>
132 const T* Foam::PtrList<T>::operator()(const label i) const
133 {
134  return ptrs_[i];
135 }
136 
137 
138 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
139 
140 template<class T>
142 :
143  ptr_(ptr)
144 {}
145 
146 template<class T>
147 inline bool Foam::PtrList<T>::iterator::operator==(const iterator& iter) const
148 {
149  return ptr_ == iter.ptr_;
150 }
151 
152 template<class T>
153 inline bool Foam::PtrList<T>::iterator::operator!=(const iterator& iter) const
154 {
155  return ptr_ != iter.ptr_;
156 }
157 
158 template<class T>
160 {
161  return **ptr_;
162 }
163 
164 template<class T>
166 {
167  return operator*();
168 }
169 
170 template<class T>
171 inline typename Foam::PtrList<T>::iterator
173 {
174  ++ptr_;
175  return *this;
176 }
177 
178 template<class T>
179 inline typename Foam::PtrList<T>::iterator
181 {
182  iterator tmp = *this;
183  ++ptr_;
184  return tmp;
185 }
186 
187 template<class T>
188 inline typename Foam::PtrList<T>::iterator
190 {
191  --ptr_;
192  return *this;
193 }
194 
195 template<class T>
196 inline typename Foam::PtrList<T>::iterator
198 {
199  iterator tmp = *this;
200  --ptr_;
201  return tmp;
202 }
203 
204 template<class T>
205 inline typename Foam::PtrList<T>::iterator
207 {
208  ptr_ += n;
209  return *this;
210 }
211 
212 template<class T>
213 inline typename Foam::PtrList<T>::iterator
214 Foam::operator+(const typename PtrList<T>::iterator& iter, label n)
215 {
216  typename PtrList<T>::iterator tmp = iter;
217  return tmp += n;
218 }
219 
220 template<class T>
221 inline typename Foam::PtrList<T>::iterator
222 Foam::operator+(label n, const typename PtrList<T>::iterator& iter)
223 {
224  typename PtrList<T>::iterator tmp = iter;
225  return tmp += n;
226 }
227 
228 template<class T>
229 inline typename Foam::PtrList<T>::iterator
231 {
232  ptr_ -= n;
233  return *this;
234 }
235 
236 template<class T>
237 inline typename Foam::PtrList<T>::iterator
238 Foam::operator-(const typename PtrList<T>::iterator& iter, label n)
239 {
240  typename PtrList<T>::iterator tmp = iter;
241  return tmp -= n;
242 }
243 
244 template<class T>
245 inline Foam::label Foam::operator-
246 (
247  const typename PtrList<T>::iterator& iter1,
248  const typename PtrList<T>::iterator& iter2
249 )
250 {
251  return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
252 }
253 
254 template<class T>
256 {
257  return *(*this + n);
258 }
259 
260 template<class T>
261 inline bool Foam::PtrList<T>::iterator::operator<(const iterator& iter) const
262 {
263  return ptr_ < iter.ptr_;
264 }
265 
266 template<class T>
267 inline bool Foam::PtrList<T>::iterator::operator>(const iterator& iter) const
268 {
269  return ptr_ > iter.ptr_;
270 }
271 
272 template<class T>
273 inline bool Foam::PtrList<T>::iterator::operator<=(const iterator& iter) const
274 {
275  return ptr_ <= iter.ptr_;
276 }
277 
278 template<class T>
279 inline bool Foam::PtrList<T>::iterator::operator>=(const iterator& iter) const
280 {
281  return ptr_ >= iter.ptr_;
282 }
283 
284 template<class T>
285 inline typename Foam::PtrList<T>::iterator
287 {
288  return ptrs_.begin();
289 }
290 
291 template<class T>
292 inline typename Foam::PtrList<T>::iterator
294 {
295  return ptrs_.end();
296 }
297 
298 
299 
300 // ************************ vim: set sw=4 sts=4 et: ************************ //