FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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