initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / UPtrList / UPtrListI.H
blob859f54fce5f7d45b2cb278be640db627183d7ceb
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 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 template<class T>
32 inline Foam::label Foam::UPtrList<T>::size() const
34     return ptrs_.size();
38 template<class T>
39 inline bool Foam::UPtrList<T>::empty() const
41     return ptrs_.empty();
45 template<class T>
46 inline void Foam::UPtrList<T>::resize(const label newSize)
48     this->setSize(newSize);
52 template<class T>
53 inline bool Foam::UPtrList<T>::set(const label i) const
55     return ptrs_[i] != NULL;
58 template<class T>
59 inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
61     T* old = ptrs_[i];
62     ptrs_[i] = ptr;
63     return old;
66 template<class T>
67 inline Foam::Xfer<Foam::UPtrList<T> > Foam::UPtrList<T>::xfer()
69     return xferMove(*this);
73 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
75 template<class T>
76 const T& Foam::UPtrList<T>::operator[](const label i) const
78     if (!ptrs_[i])
79     {
80         FatalErrorIn("UPtrList::operator[] const")
81             << "hanging pointer, cannot dereference"
82             << abort(FatalError);
83     }
85     return *(ptrs_[i]);
89 template<class T>
90 T& Foam::UPtrList<T>::operator[](const label i)
92     if (!ptrs_[i])
93     {
94         FatalErrorIn("UPtrList::operator[]")
95             << "hanging pointer, cannot dereference"
96             << abort(FatalError);
97     }
99     return *(ptrs_[i]);
103 template<class T>
104 const T* Foam::UPtrList<T>::operator()(const label i) const
106     return ptrs_[i];
110 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
112 template<class T>
113 inline Foam::UPtrList<T>::iterator::iterator(T** ptr)
115     ptr_(ptr)
118 template<class T>
119 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
121     return ptr_ == iter.ptr_;
124 template<class T>
125 inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
127     return ptr_ != iter.ptr_;
130 template<class T>
131 inline T& Foam::UPtrList<T>::iterator::operator*()
133     return **ptr_;
136 template<class T>
137 inline T& Foam::UPtrList<T>::iterator::operator()()
139     return operator*();
142 template<class T>
143 inline typename Foam::UPtrList<T>::iterator
144 Foam::UPtrList<T>::iterator::operator++()
146     ++ptr_;
147     return *this;
150 template<class T>
151 inline typename Foam::UPtrList<T>::iterator
152 Foam::UPtrList<T>::iterator::operator++(int)
154     iterator tmp = *this;
155     ++ptr_;
156     return tmp;
159 template<class T>
160 inline typename Foam::UPtrList<T>::iterator
161 Foam::UPtrList<T>::iterator::operator--()
163     --ptr_;
164     return *this;
167 template<class T>
168 inline typename Foam::UPtrList<T>::iterator
169 Foam::UPtrList<T>::iterator::operator--(int)
171     iterator tmp = *this;
172     --ptr_;
173     return tmp;
176 template<class T>
177 inline typename Foam::UPtrList<T>::iterator
178 Foam::UPtrList<T>::iterator::operator+=(label n)
180     ptr_ += n;
181     return *this;
184 template<class T>
185 inline typename Foam::UPtrList<T>::iterator
186 Foam::operator+(const typename UPtrList<T>::iterator& iter, label n)
188     typename UPtrList<T>::iterator tmp = iter;
189     return tmp += n;
192 template<class T>
193 inline typename Foam::UPtrList<T>::iterator
194 Foam::operator+(label n, const typename UPtrList<T>::iterator& iter)
196     typename UPtrList<T>::iterator tmp = iter;
197     return tmp += n;
200 template<class T>
201 inline typename Foam::UPtrList<T>::iterator
202 Foam::UPtrList<T>::iterator::operator-=(label n)
204     ptr_ -= n;
205     return *this;
208 template<class T>
209 inline typename Foam::UPtrList<T>::iterator
210 Foam::operator-(const typename UPtrList<T>::iterator& iter, label n)
212     typename UPtrList<T>::iterator tmp = iter;
213     return tmp -= n;
216 template<class T>
217 inline Foam::label Foam::operator-
219     const typename UPtrList<T>::iterator& iter1,
220     const typename UPtrList<T>::iterator& iter2
223     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
226 template<class T>
227 inline T& Foam::UPtrList<T>::iterator::operator[](label n)
229     return *(*this + n);
232 template<class T>
233 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
235     return ptr_ < iter.ptr_;
238 template<class T>
239 inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
241     return ptr_ > iter.ptr_;
244 template<class T>
245 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
247     return ptr_ <= iter.ptr_;
250 template<class T>
251 inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
253     return ptr_ >= iter.ptr_;
256 template<class T>
257 inline typename Foam::UPtrList<T>::iterator
258 Foam::UPtrList<T>::begin()
260     return ptrs_.begin();
263 template<class T>
264 inline typename Foam::UPtrList<T>::iterator
265 Foam::UPtrList<T>::end()
267     return ptrs_.end();
271 // ************************************************************************* //