initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / PtrList / PtrListI.H
blobd450cdd09fe7107d975d338031f066878be7fca1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "error.H"
29 #include "autoPtr.H"
30 #include "tmp.H"
32 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
34 template<class T>
35 inline Foam::label Foam::PtrList<T>::size() const
37     return ptrs_.size();
41 template<class T>
42 inline bool Foam::PtrList<T>::empty() const
44     return ptrs_.empty();
48 template<class T>
49 inline void Foam::PtrList<T>::resize(const label newSize)
51     this->setSize(newSize);
55 template<class T>
56 inline bool Foam::PtrList<T>::set(const label i) const
58     return ptrs_[i] != NULL;
62 template<class T>
63 inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
65     autoPtr<T> old(ptrs_[i]);
67     ptrs_[i] = ptr;
69     return old;
73 template<class T>
74 inline Foam::autoPtr<T> Foam::PtrList<T>::set
76     const label i,
77     const autoPtr<T>& aptr
80     return set(i, const_cast<autoPtr<T>&>(aptr).ptr());
84 template<class T>
85 inline Foam::autoPtr<T> Foam::PtrList<T>::set
87     const label i,
88     const tmp<T>& t
91     return set(i, const_cast<tmp<T>&>(t).ptr());
95 template<class T>
96 inline Foam::Xfer<Foam::PtrList<T> > Foam::PtrList<T>::xfer()
98     return xferMove(*this);
102 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
104 template<class T>
105 const T& Foam::PtrList<T>::operator[](const label i) const
107     if (!ptrs_[i])
108     {
109         FatalErrorIn("PtrList::operator[] const")
110             << "hanging pointer, cannot dereference"
111             << abort(FatalError);
112     }
114     return *(ptrs_[i]);
118 template<class T>
119 T& Foam::PtrList<T>::operator[](const label i)
121     if (!ptrs_[i])
122     {
123         FatalErrorIn("PtrList::operator[]")
124             << "hanging pointer, cannot dereference"
125             << abort(FatalError);
126     }
128     return *(ptrs_[i]);
132 template<class T>
133 const T* Foam::PtrList<T>::operator()(const label i) const
135     return ptrs_[i];
139 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
141 template<class T>
142 inline Foam::PtrList<T>::iterator::iterator(T** ptr)
144     ptr_(ptr)
147 template<class T>
148 inline bool Foam::PtrList<T>::iterator::operator==(const iterator& iter) const
150     return ptr_ == iter.ptr_;
153 template<class T>
154 inline bool Foam::PtrList<T>::iterator::operator!=(const iterator& iter) const
156     return ptr_ != iter.ptr_;
159 template<class T>
160 inline T& Foam::PtrList<T>::iterator::operator*()
162     return **ptr_;
165 template<class T>
166 inline T& Foam::PtrList<T>::iterator::operator()()
168     return operator*();
171 template<class T>
172 inline typename Foam::PtrList<T>::iterator
173 Foam::PtrList<T>::iterator::operator++()
175     ++ptr_;
176     return *this;
179 template<class T>
180 inline typename Foam::PtrList<T>::iterator
181 Foam::PtrList<T>::iterator::operator++(int)
183     iterator tmp = *this;
184     ++ptr_;
185     return tmp;
188 template<class T>
189 inline typename Foam::PtrList<T>::iterator
190 Foam::PtrList<T>::iterator::operator--()
192     --ptr_;
193     return *this;
196 template<class T>
197 inline typename Foam::PtrList<T>::iterator
198 Foam::PtrList<T>::iterator::operator--(int)
200     iterator tmp = *this;
201     --ptr_;
202     return tmp;
205 template<class T>
206 inline typename Foam::PtrList<T>::iterator
207 Foam::PtrList<T>::iterator::operator+=(label n)
209     ptr_ += n;
210     return *this;
213 template<class T>
214 inline typename Foam::PtrList<T>::iterator
215 Foam::operator+(const typename PtrList<T>::iterator& iter, label n)
217     typename PtrList<T>::iterator tmp = iter;
218     return tmp += n;
221 template<class T>
222 inline typename Foam::PtrList<T>::iterator
223 Foam::operator+(label n, const typename PtrList<T>::iterator& iter)
225     typename PtrList<T>::iterator tmp = iter;
226     return tmp += n;
229 template<class T>
230 inline typename Foam::PtrList<T>::iterator
231 Foam::PtrList<T>::iterator::operator-=(label n)
233     ptr_ -= n;
234     return *this;
237 template<class T>
238 inline typename Foam::PtrList<T>::iterator
239 Foam::operator-(const typename PtrList<T>::iterator& iter, label n)
241     typename PtrList<T>::iterator tmp = iter;
242     return tmp -= n;
245 template<class T>
246 inline Foam::label Foam::operator-
248     const typename PtrList<T>::iterator& iter1,
249     const typename PtrList<T>::iterator& iter2
252     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
255 template<class T>
256 inline T& Foam::PtrList<T>::iterator::operator[](label n)
258     return *(*this + n);
261 template<class T>
262 inline bool Foam::PtrList<T>::iterator::operator<(const iterator& iter) const
264     return ptr_ < iter.ptr_;
267 template<class T>
268 inline bool Foam::PtrList<T>::iterator::operator>(const iterator& iter) const
270     return ptr_ > iter.ptr_;
273 template<class T>
274 inline bool Foam::PtrList<T>::iterator::operator<=(const iterator& iter) const
276     return ptr_ <= iter.ptr_;
279 template<class T>
280 inline bool Foam::PtrList<T>::iterator::operator>=(const iterator& iter) const
282     return ptr_ >= iter.ptr_;
285 template<class T>
286 inline typename Foam::PtrList<T>::iterator
287 Foam::PtrList<T>::begin()
289     return ptrs_.begin();
292 template<class T>
293 inline typename Foam::PtrList<T>::iterator
294 Foam::PtrList<T>::end()
296     return ptrs_.end();
301 // ************************************************************************* //