OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

UPtrListI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "error.H"
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 template<class T>
00032 inline Foam::label Foam::UPtrList<T>::size() const
00033 {
00034     return ptrs_.size();
00035 }
00036 
00037 
00038 template<class T>
00039 inline bool Foam::UPtrList<T>::empty() const
00040 {
00041     return ptrs_.empty();
00042 }
00043 
00044 
00045 template<class T>
00046 inline void Foam::UPtrList<T>::resize(const label newSize)
00047 {
00048     this->setSize(newSize);
00049 }
00050 
00051 
00052 template<class T>
00053 inline bool Foam::UPtrList<T>::set(const label i) const
00054 {
00055     return ptrs_[i] != NULL;
00056 }
00057 
00058 template<class T>
00059 inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
00060 {
00061     T* old = ptrs_[i];
00062     ptrs_[i] = ptr;
00063     return old;
00064 }
00065 
00066 template<class T>
00067 inline Foam::Xfer<Foam::UPtrList<T> > Foam::UPtrList<T>::xfer()
00068 {
00069     return xferMove(*this);
00070 }
00071 
00072 
00073 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00074 
00075 template<class T>
00076 const T& Foam::UPtrList<T>::operator[](const label i) const
00077 {
00078     if (!ptrs_[i])
00079     {
00080         FatalErrorIn("UPtrList::operator[] const")
00081             << "hanging pointer, cannot dereference"
00082             << abort(FatalError);
00083     }
00084 
00085     return *(ptrs_[i]);
00086 }
00087 
00088 
00089 template<class T>
00090 T& Foam::UPtrList<T>::operator[](const label i)
00091 {
00092     if (!ptrs_[i])
00093     {
00094         FatalErrorIn("UPtrList::operator[]")
00095             << "hanging pointer, cannot dereference"
00096             << abort(FatalError);
00097     }
00098 
00099     return *(ptrs_[i]);
00100 }
00101 
00102 
00103 template<class T>
00104 const T* Foam::UPtrList<T>::operator()(const label i) const
00105 {
00106     return ptrs_[i];
00107 }
00108 
00109 
00110 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
00111 
00112 template<class T>
00113 inline Foam::UPtrList<T>::iterator::iterator(T** ptr)
00114 :
00115     ptr_(ptr)
00116 {}
00117 
00118 template<class T>
00119 inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
00120 {
00121     return ptr_ == iter.ptr_;
00122 }
00123 
00124 template<class T>
00125 inline bool Foam::UPtrList<T>::iterator::operator!=(const iterator& iter) const
00126 {
00127     return ptr_ != iter.ptr_;
00128 }
00129 
00130 template<class T>
00131 inline T& Foam::UPtrList<T>::iterator::operator*()
00132 {
00133     return **ptr_;
00134 }
00135 
00136 template<class T>
00137 inline T& Foam::UPtrList<T>::iterator::operator()()
00138 {
00139     return operator*();
00140 }
00141 
00142 template<class T>
00143 inline typename Foam::UPtrList<T>::iterator
00144 Foam::UPtrList<T>::iterator::operator++()
00145 {
00146     ++ptr_;
00147     return *this;
00148 }
00149 
00150 template<class T>
00151 inline typename Foam::UPtrList<T>::iterator
00152 Foam::UPtrList<T>::iterator::operator++(int)
00153 {
00154     iterator tmp = *this;
00155     ++ptr_;
00156     return tmp;
00157 }
00158 
00159 template<class T>
00160 inline typename Foam::UPtrList<T>::iterator
00161 Foam::UPtrList<T>::iterator::operator--()
00162 {
00163     --ptr_;
00164     return *this;
00165 }
00166 
00167 template<class T>
00168 inline typename Foam::UPtrList<T>::iterator
00169 Foam::UPtrList<T>::iterator::operator--(int)
00170 {
00171     iterator tmp = *this;
00172     --ptr_;
00173     return tmp;
00174 }
00175 
00176 template<class T>
00177 inline typename Foam::UPtrList<T>::iterator
00178 Foam::UPtrList<T>::iterator::operator+=(label n)
00179 {
00180     ptr_ += n;
00181     return *this;
00182 }
00183 
00184 template<class T>
00185 inline typename Foam::UPtrList<T>::iterator
00186 Foam::operator+(const typename UPtrList<T>::iterator& iter, label n)
00187 {
00188     typename UPtrList<T>::iterator tmp = iter;
00189     return tmp += n;
00190 }
00191 
00192 template<class T>
00193 inline typename Foam::UPtrList<T>::iterator
00194 Foam::operator+(label n, const typename UPtrList<T>::iterator& iter)
00195 {
00196     typename UPtrList<T>::iterator tmp = iter;
00197     return tmp += n;
00198 }
00199 
00200 template<class T>
00201 inline typename Foam::UPtrList<T>::iterator
00202 Foam::UPtrList<T>::iterator::operator-=(label n)
00203 {
00204     ptr_ -= n;
00205     return *this;
00206 }
00207 
00208 template<class T>
00209 inline typename Foam::UPtrList<T>::iterator
00210 Foam::operator-(const typename UPtrList<T>::iterator& iter, label n)
00211 {
00212     typename UPtrList<T>::iterator tmp = iter;
00213     return tmp -= n;
00214 }
00215 
00216 template<class T>
00217 inline Foam::label Foam::operator-
00218 (
00219     const typename UPtrList<T>::iterator& iter1,
00220     const typename UPtrList<T>::iterator& iter2
00221 )
00222 {
00223     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
00224 }
00225 
00226 template<class T>
00227 inline T& Foam::UPtrList<T>::iterator::operator[](label n)
00228 {
00229     return *(*this + n);
00230 }
00231 
00232 template<class T>
00233 inline bool Foam::UPtrList<T>::iterator::operator<(const iterator& iter) const
00234 {
00235     return ptr_ < iter.ptr_;
00236 }
00237 
00238 template<class T>
00239 inline bool Foam::UPtrList<T>::iterator::operator>(const iterator& iter) const
00240 {
00241     return ptr_ > iter.ptr_;
00242 }
00243 
00244 template<class T>
00245 inline bool Foam::UPtrList<T>::iterator::operator<=(const iterator& iter) const
00246 {
00247     return ptr_ <= iter.ptr_;
00248 }
00249 
00250 template<class T>
00251 inline bool Foam::UPtrList<T>::iterator::operator>=(const iterator& iter) const
00252 {
00253     return ptr_ >= iter.ptr_;
00254 }
00255 
00256 template<class T>
00257 inline typename Foam::UPtrList<T>::iterator
00258 Foam::UPtrList<T>::begin()
00259 {
00260     return ptrs_.begin();
00261 }
00262 
00263 template<class T>
00264 inline typename Foam::UPtrList<T>::iterator
00265 Foam::UPtrList<T>::end()
00266 {
00267     return ptrs_.end();
00268 }
00269 
00270 
00271 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd