FreeFOAM The Cross-Platform CFD Toolkit
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) 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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class T>
31 inline Foam::label Foam::UPtrList<T>::size() const
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>
45 inline void Foam::UPtrList<T>::resize(const label newSize)
46 {
47  this->setSize(newSize);
48 }
49 
50 
51 template<class T>
52 inline bool Foam::UPtrList<T>::set(const label i) const
53 {
54  return ptrs_[i] != NULL;
55 }
56 
57 template<class T>
58 inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
59 {
60  T* old = ptrs_[i];
61  ptrs_[i] = ptr;
62  return old;
63 }
64 
65 template<class T>
67 {
68  return xferMove(*this);
69 }
70 
71 
72 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
73 
74 template<class T>
75 const T& Foam::UPtrList<T>::operator[](const label i) const
76 {
77  if (!ptrs_[i])
78  {
79  FatalErrorIn("UPtrList::operator[] const")
80  << "hanging pointer, cannot dereference"
81  << abort(FatalError);
82  }
83 
84  return *(ptrs_[i]);
85 }
86 
87 
88 template<class T>
90 {
91  if (!ptrs_[i])
92  {
93  FatalErrorIn("UPtrList::operator[]")
94  << "hanging pointer, cannot dereference"
95  << abort(FatalError);
96  }
97 
98  return *(ptrs_[i]);
99 }
100 
101 
102 template<class T>
103 const T* Foam::UPtrList<T>::operator()(const label i) const
104 {
105  return ptrs_[i];
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
110 
111 template<class T>
113 :
114  ptr_(ptr)
115 {}
116 
117 template<class T>
118 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
119 {
120  return ptr_ == iter.ptr_;
121 }
122 
123 template<class T>
124 inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
125 {
126  return ptr_ != iter.ptr_;
127 }
128 
129 template<class T>
131 {
132  return **ptr_;
133 }
134 
135 template<class T>
137 {
138  return operator*();
139 }
140 
141 template<class T>
142 inline typename Foam::UPtrList<T>::iterator
144 {
145  ++ptr_;
146  return *this;
147 }
148 
149 template<class T>
150 inline typename Foam::UPtrList<T>::iterator
152 {
153  iterator tmp = *this;
154  ++ptr_;
155  return tmp;
156 }
157 
158 template<class T>
159 inline typename Foam::UPtrList<T>::iterator
161 {
162  --ptr_;
163  return *this;
164 }
165 
166 template<class T>
167 inline typename Foam::UPtrList<T>::iterator
169 {
170  iterator tmp = *this;
171  --ptr_;
172  return tmp;
173 }
174 
175 template<class T>
176 inline typename Foam::UPtrList<T>::iterator
178 {
179  ptr_ += n;
180  return *this;
181 }
182 
183 template<class T>
184 inline typename Foam::UPtrList<T>::iterator
185 Foam::operator+(const typename UPtrList<T>::iterator& iter, label n)
186 {
187  typename UPtrList<T>::iterator tmp = iter;
188  return tmp += n;
189 }
190 
191 template<class T>
192 inline typename Foam::UPtrList<T>::iterator
193 Foam::operator+(label n, const typename UPtrList<T>::iterator& iter)
194 {
195  typename UPtrList<T>::iterator tmp = iter;
196  return tmp += n;
197 }
198 
199 template<class T>
200 inline typename Foam::UPtrList<T>::iterator
202 {
203  ptr_ -= n;
204  return *this;
205 }
206 
207 template<class T>
208 inline typename Foam::UPtrList<T>::iterator
209 Foam::operator-(const typename UPtrList<T>::iterator& iter, label n)
210 {
211  typename UPtrList<T>::iterator tmp = iter;
212  return tmp -= n;
213 }
214 
215 template<class T>
216 inline Foam::label Foam::operator-
217 (
218  const typename UPtrList<T>::iterator& iter1,
219  const typename UPtrList<T>::iterator& iter2
220 )
221 {
222  return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
223 }
224 
225 template<class T>
227 {
228  return *(*this + n);
229 }
230 
231 template<class T>
232 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
233 {
234  return ptr_ < iter.ptr_;
235 }
236 
237 template<class T>
238 inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
239 {
240  return ptr_ > iter.ptr_;
241 }
242 
243 template<class T>
244 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
245 {
246  return ptr_ <= iter.ptr_;
247 }
248 
249 template<class T>
250 inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
251 {
252  return ptr_ >= iter.ptr_;
253 }
254 
255 template<class T>
256 inline typename Foam::UPtrList<T>::iterator
258 {
259  return ptrs_.begin();
260 }
261 
262 template<class T>
263 inline typename Foam::UPtrList<T>::iterator
265 {
266  return ptrs_.end();
267 }
268 
269 
270 // ************************ vim: set sw=4 sts=4 et: ************************ //