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

PtrListI.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 #include "autoPtr.H"
00030 #include "tmp.H"
00031 
00032 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00033 
00034 template<class T>
00035 inline Foam::label Foam::PtrList<T>::size() const
00036 {
00037     return ptrs_.size();
00038 }
00039 
00040 
00041 template<class T>
00042 inline bool Foam::PtrList<T>::empty() const
00043 {
00044     return ptrs_.empty();
00045 }
00046 
00047 
00048 template<class T>
00049 inline void Foam::PtrList<T>::resize(const label newSize)
00050 {
00051     this->setSize(newSize);
00052 }
00053 
00054 
00055 template<class T>
00056 inline bool Foam::PtrList<T>::set(const label i) const
00057 {
00058     return ptrs_[i] != NULL;
00059 }
00060 
00061 
00062 template<class T>
00063 inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
00064 {
00065     autoPtr<T> old(ptrs_[i]);
00066 
00067     ptrs_[i] = ptr;
00068 
00069     return old;
00070 }
00071 
00072 
00073 template<class T>
00074 inline Foam::autoPtr<T> Foam::PtrList<T>::set
00075 (
00076     const label i,
00077     const autoPtr<T>& aptr
00078 )
00079 {
00080     return set(i, const_cast<autoPtr<T>&>(aptr).ptr());
00081 }
00082 
00083 
00084 template<class T>
00085 inline Foam::autoPtr<T> Foam::PtrList<T>::set
00086 (
00087     const label i,
00088     const tmp<T>& t
00089 )
00090 {
00091     return set(i, const_cast<tmp<T>&>(t).ptr());
00092 }
00093 
00094 
00095 template<class T>
00096 inline Foam::Xfer<Foam::PtrList<T> > Foam::PtrList<T>::xfer()
00097 {
00098     return xferMove(*this);
00099 }
00100 
00101 
00102 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00103 
00104 template<class T>
00105 const T& Foam::PtrList<T>::operator[](const label i) const
00106 {
00107     if (!ptrs_[i])
00108     {
00109         FatalErrorIn("PtrList::operator[] const")
00110             << "hanging pointer, cannot dereference"
00111             << abort(FatalError);
00112     }
00113 
00114     return *(ptrs_[i]);
00115 }
00116 
00117 
00118 template<class T>
00119 T& Foam::PtrList<T>::operator[](const label i)
00120 {
00121     if (!ptrs_[i])
00122     {
00123         FatalErrorIn("PtrList::operator[]")
00124             << "hanging pointer, cannot dereference"
00125             << abort(FatalError);
00126     }
00127 
00128     return *(ptrs_[i]);
00129 }
00130 
00131 
00132 template<class T>
00133 const T* Foam::PtrList<T>::operator()(const label i) const
00134 {
00135     return ptrs_[i];
00136 }
00137 
00138 
00139 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
00140 
00141 template<class T>
00142 inline Foam::PtrList<T>::iterator::iterator(T** ptr)
00143 :
00144     ptr_(ptr)
00145 {}
00146 
00147 template<class T>
00148 inline bool Foam::PtrList<T>::iterator::operator==(const iterator& iter) const
00149 {
00150     return ptr_ == iter.ptr_;
00151 }
00152 
00153 template<class T>
00154 inline bool Foam::PtrList<T>::iterator::operator!=(const iterator& iter) const
00155 {
00156     return ptr_ != iter.ptr_;
00157 }
00158 
00159 template<class T>
00160 inline T& Foam::PtrList<T>::iterator::operator*()
00161 {
00162     return **ptr_;
00163 }
00164 
00165 template<class T>
00166 inline T& Foam::PtrList<T>::iterator::operator()()
00167 {
00168     return operator*();
00169 }
00170 
00171 template<class T>
00172 inline typename Foam::PtrList<T>::iterator
00173 Foam::PtrList<T>::iterator::operator++()
00174 {
00175     ++ptr_;
00176     return *this;
00177 }
00178 
00179 template<class T>
00180 inline typename Foam::PtrList<T>::iterator
00181 Foam::PtrList<T>::iterator::operator++(int)
00182 {
00183     iterator tmp = *this;
00184     ++ptr_;
00185     return tmp;
00186 }
00187 
00188 template<class T>
00189 inline typename Foam::PtrList<T>::iterator
00190 Foam::PtrList<T>::iterator::operator--()
00191 {
00192     --ptr_;
00193     return *this;
00194 }
00195 
00196 template<class T>
00197 inline typename Foam::PtrList<T>::iterator
00198 Foam::PtrList<T>::iterator::operator--(int)
00199 {
00200     iterator tmp = *this;
00201     --ptr_;
00202     return tmp;
00203 }
00204 
00205 template<class T>
00206 inline typename Foam::PtrList<T>::iterator
00207 Foam::PtrList<T>::iterator::operator+=(label n)
00208 {
00209     ptr_ += n;
00210     return *this;
00211 }
00212 
00213 template<class T>
00214 inline typename Foam::PtrList<T>::iterator
00215 Foam::operator+(const typename PtrList<T>::iterator& iter, label n)
00216 {
00217     typename PtrList<T>::iterator tmp = iter;
00218     return tmp += n;
00219 }
00220 
00221 template<class T>
00222 inline typename Foam::PtrList<T>::iterator
00223 Foam::operator+(label n, const typename PtrList<T>::iterator& iter)
00224 {
00225     typename PtrList<T>::iterator tmp = iter;
00226     return tmp += n;
00227 }
00228 
00229 template<class T>
00230 inline typename Foam::PtrList<T>::iterator
00231 Foam::PtrList<T>::iterator::operator-=(label n)
00232 {
00233     ptr_ -= n;
00234     return *this;
00235 }
00236 
00237 template<class T>
00238 inline typename Foam::PtrList<T>::iterator
00239 Foam::operator-(const typename PtrList<T>::iterator& iter, label n)
00240 {
00241     typename PtrList<T>::iterator tmp = iter;
00242     return tmp -= n;
00243 }
00244 
00245 template<class T>
00246 inline Foam::label Foam::operator-
00247 (
00248     const typename PtrList<T>::iterator& iter1,
00249     const typename PtrList<T>::iterator& iter2
00250 )
00251 {
00252     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
00253 }
00254 
00255 template<class T>
00256 inline T& Foam::PtrList<T>::iterator::operator[](label n)
00257 {
00258     return *(*this + n);
00259 }
00260 
00261 template<class T>
00262 inline bool Foam::PtrList<T>::iterator::operator<(const iterator& iter) const
00263 {
00264     return ptr_ < iter.ptr_;
00265 }
00266 
00267 template<class T>
00268 inline bool Foam::PtrList<T>::iterator::operator>(const iterator& iter) const
00269 {
00270     return ptr_ > iter.ptr_;
00271 }
00272 
00273 template<class T>
00274 inline bool Foam::PtrList<T>::iterator::operator<=(const iterator& iter) const
00275 {
00276     return ptr_ <= iter.ptr_;
00277 }
00278 
00279 template<class T>
00280 inline bool Foam::PtrList<T>::iterator::operator>=(const iterator& iter) const
00281 {
00282     return ptr_ >= iter.ptr_;
00283 }
00284 
00285 template<class T>
00286 inline typename Foam::PtrList<T>::iterator
00287 Foam::PtrList<T>::begin()
00288 {
00289     return ptrs_.begin();
00290 }
00291 
00292 template<class T>
00293 inline typename Foam::PtrList<T>::iterator
00294 Foam::PtrList<T>::end()
00295 {
00296     return ptrs_.end();
00297 }
00298 
00299 
00300 
00301 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd