initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / Lists / PtrList / PtrListI.H
blob245c556b46cc6bd4e870312aea1a0875b307f35f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 template<class T>
40 inline label PtrList<T>::size() const
42     return ptrs_.size();
46 template<class T>
47 inline bool PtrList<T>::set(const label i) const
49     return ptrs_[i] != NULL;
53 template<class T>
54 inline autoPtr<T> PtrList<T>::set(const label i, T* ptr)
56     autoPtr<T> old(ptrs_[i]);
58     ptrs_[i] = ptr;
60     return old;
64 template<class T>
65 inline autoPtr<T> PtrList<T>::set(const label i, const autoPtr<T>& aptr)
67     return set(i, const_cast<autoPtr<T>&>(aptr).ptr());
71 template<class T>
72 inline autoPtr<T> PtrList<T>::set(const label i, const tmp<T>& t)
74     return set(i, const_cast<tmp<T>&>(t).ptr());
78 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
80 template<class T>
81 const T& PtrList<T>::operator[](const label i) const
83     if (!ptrs_[i])
84     {
85         FatalErrorIn("PtrList::operator[] const")
86             << "hanging pointer, cannot dereference"
87             << abort(FatalError);
88     }
90     return *(ptrs_[i]);
94 template<class T>
95 T& PtrList<T>::operator[](const label i)
97     if (!ptrs_[i])
98     {
99         FatalErrorIn("PtrList::operator[]")
100             << "hanging pointer, cannot dereference"
101             << abort(FatalError);
102     }
104     return *(ptrs_[i]);
108 template<class T>
109 const T* PtrList<T>::operator()(const label i) const
111     return ptrs_[i];
115 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
117 template<class T>
118 inline PtrList<T>::iterator::iterator(T** ptr)
120     ptr_(ptr)
123 template<class T>
124 inline bool PtrList<T>::iterator::operator==(const iterator& iter) const
126     return ptr_ == iter.ptr_;
129 template<class T>
130 inline bool PtrList<T>::iterator::operator!=(const iterator& iter) const
132     return ptr_ != iter.ptr_;
135 template<class T>
136 inline T& PtrList<T>::iterator::operator*()
138     return **ptr_;
141 template<class T>
142 inline T& PtrList<T>::iterator::operator()()
144     return operator*();
147 template<class T>
148 inline typename PtrList<T>::iterator
149 PtrList<T>::iterator::operator++()
151     ++ptr_;
152     return *this;
155 template<class T>
156 inline typename PtrList<T>::iterator
157 PtrList<T>::iterator::operator++(int)
159     iterator tmp = *this;
160     ++ptr_;
161     return tmp;
164 template<class T>
165 inline typename PtrList<T>::iterator
166 PtrList<T>::iterator::operator--()
168     --ptr_;
169     return *this;
172 template<class T>
173 inline typename PtrList<T>::iterator
174 PtrList<T>::iterator::operator--(int)
176     iterator tmp = *this;
177     --ptr_;
178     return tmp;
181 template<class T>
182 inline typename PtrList<T>::iterator
183 PtrList<T>::iterator::operator+=(label n)
185     ptr_ += n;
186     return *this;
189 template<class T>
190 inline typename PtrList<T>::iterator
191 operator+(const typename PtrList<T>::iterator& iter, label n)
193     typename PtrList<T>::iterator tmp = iter;
194     return tmp += n;
197 template<class T>
198 inline typename PtrList<T>::iterator
199 operator+(label n, const typename PtrList<T>::iterator& iter)
201     typename PtrList<T>::iterator tmp = iter;
202     return tmp += n;
205 template<class T>
206 inline typename PtrList<T>::iterator
207 PtrList<T>::iterator::operator-=(label n)
209     ptr_ -= n;
210     return *this;
213 template<class T>
214 inline typename PtrList<T>::iterator
215 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 label operator-
224     const typename PtrList<T>::iterator& iter1,
225     const typename PtrList<T>::iterator& iter2
228     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
231 template<class T>
232 inline T& PtrList<T>::iterator::operator[](label n)
234     return *(*this + n);
237 template<class T>
238 inline bool PtrList<T>::iterator::operator<(const iterator& iter) const
240     return ptr_ < iter.ptr_;
243 template<class T>
244 inline bool PtrList<T>::iterator::operator>(const iterator& iter) const
246     return ptr_ > iter.ptr_;
249 template<class T>
250 inline bool PtrList<T>::iterator::operator<=(const iterator& iter) const
252     return ptr_ <= iter.ptr_;
255 template<class T>
256 inline bool PtrList<T>::iterator::operator>=(const iterator& iter) const
258     return ptr_ >= iter.ptr_;
261 template<class T>
262 inline typename PtrList<T>::iterator PtrList<T>::begin()
264     return ptrs_.begin();
267 template<class T>
268 inline typename PtrList<T>::iterator PtrList<T>::end()
270     return ptrs_.end();
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 } // End namespace Foam
278 // ************************************************************************* //