initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / Lists / UPtrList / UPtrListI.H
blob94c4d553f70f82406853c401f0d9d040eabfb49b
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 template<class T>
37 inline label UPtrList<T>::size() const
39     return ptrs_.size();
43 template<class T>
44 inline bool UPtrList<T>::set(const label i) const
46     return ptrs_[i] != NULL;
50 template<class T>
51 inline T* UPtrList<T>::set(const label i, T* ptr)
53     T* old = ptrs_[i];
54     ptrs_[i] = ptr;
55     return old;
59 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
61 template<class T>
62 const T& UPtrList<T>::operator[](const label i) const
64     if (!ptrs_[i])
65     {
66         FatalErrorIn("UPtrList::operator[] const")
67             << "hanging pointer, cannot dereference"
68             << abort(FatalError);
69     }
71     return *(ptrs_[i]);
75 template<class T>
76 T& UPtrList<T>::operator[](const label i)
78     if (!ptrs_[i])
79     {
80         FatalErrorIn("UPtrList::operator[]")
81             << "hanging pointer, cannot dereference"
82             << abort(FatalError);
83     }
85     return *(ptrs_[i]);
89 template<class T>
90 const T* UPtrList<T>::operator()(const label i) const
92     return ptrs_[i];
96 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
98 template<class T>
99 inline UPtrList<T>::iterator::iterator(T** ptr)
101     ptr_(ptr)
104 template<class T>
105 inline bool UPtrList<T>::iterator::operator==(const iterator& iter) const
107     return ptr_ == iter.ptr_;
110 template<class T>
111 inline bool UPtrList<T>::iterator::operator!=(const iterator& iter) const
113     return ptr_ != iter.ptr_;
116 template<class T>
117 inline T& UPtrList<T>::iterator::operator*()
119     return **ptr_;
122 template<class T>
123 inline T& UPtrList<T>::iterator::operator()()
125     return operator*();
128 template<class T>
129 inline typename UPtrList<T>::iterator
130 UPtrList<T>::iterator::operator++()
132     ++ptr_;
133     return *this;
136 template<class T>
137 inline typename UPtrList<T>::iterator
138 UPtrList<T>::iterator::operator++(int)
140     iterator tmp = *this;
141     ++ptr_;
142     return tmp;
145 template<class T>
146 inline typename UPtrList<T>::iterator
147 UPtrList<T>::iterator::operator--()
149     --ptr_;
150     return *this;
153 template<class T>
154 inline typename UPtrList<T>::iterator
155 UPtrList<T>::iterator::operator--(int)
157     iterator tmp = *this;
158     --ptr_;
159     return tmp;
162 template<class T>
163 inline typename UPtrList<T>::iterator
164 UPtrList<T>::iterator::operator+=(label n)
166     ptr_ += n;
167     return *this;
170 template<class T>
171 inline typename UPtrList<T>::iterator
172 operator+(const typename UPtrList<T>::iterator& iter, label n)
174     typename UPtrList<T>::iterator tmp = iter;
175     return tmp += n;
178 template<class T>
179 inline typename UPtrList<T>::iterator
180 operator+(label n, const typename UPtrList<T>::iterator& iter)
182     typename UPtrList<T>::iterator tmp = iter;
183     return tmp += n;
186 template<class T>
187 inline typename UPtrList<T>::iterator
188 UPtrList<T>::iterator::operator-=(label n)
190     ptr_ -= n;
191     return *this;
194 template<class T>
195 inline typename UPtrList<T>::iterator
196 operator-(const typename UPtrList<T>::iterator& iter, label n)
198     typename UPtrList<T>::iterator tmp = iter;
199     return tmp -= n;
202 template<class T>
203 inline label operator-
205     const typename UPtrList<T>::iterator& iter1,
206     const typename UPtrList<T>::iterator& iter2
209     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
212 template<class T>
213 inline T& UPtrList<T>::iterator::operator[](label n)
215     return *(*this + n);
218 template<class T>
219 inline bool UPtrList<T>::iterator::operator<(const iterator& iter) const
221     return ptr_ < iter.ptr_;
224 template<class T>
225 inline bool UPtrList<T>::iterator::operator>(const iterator& iter) const
227     return ptr_ > iter.ptr_;
230 template<class T>
231 inline bool UPtrList<T>::iterator::operator<=(const iterator& iter) const
233     return ptr_ <= iter.ptr_;
236 template<class T>
237 inline bool UPtrList<T>::iterator::operator>=(const iterator& iter) const
239     return ptr_ >= iter.ptr_;
242 template<class T>
243 inline typename UPtrList<T>::iterator UPtrList<T>::begin()
245     return ptrs_.begin();
248 template<class T>
249 inline typename UPtrList<T>::iterator UPtrList<T>::end()
251     return ptrs_.end();
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 } // End namespace Foam
259 // ************************************************************************* //