OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00035 
00036 template<class T>
00037 inline label UPtrList<T>::size() const
00038 {
00039     return ptrs_.size();
00040 }
00041 
00042 
00043 template<class T>
00044 inline bool UPtrList<T>::set(const label i) const
00045 {
00046     return ptrs_[i] != NULL;
00047 }
00048 
00049 
00050 template<class T>
00051 inline T* UPtrList<T>::set(const label i, T* ptr)
00052 {
00053     T* old = ptrs_[i];
00054     ptrs_[i] = ptr;
00055     return old;
00056 }
00057 
00058 
00059 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00060 
00061 template<class T>
00062 const T& UPtrList<T>::operator[](const label i) const
00063 {
00064     if (!ptrs_[i])
00065     {
00066         FatalErrorIn("UPtrList::operator[] const")
00067             << "hanging pointer, cannot dereference"
00068             << abort(FatalError);
00069     }
00070 
00071     return *(ptrs_[i]);
00072 }
00073 
00074 
00075 template<class T>
00076 T& UPtrList<T>::operator[](const label i)
00077 {
00078     if (!ptrs_[i])
00079     {
00080         FatalErrorIn("UPtrList::operator[]")
00081             << "hanging pointer, cannot dereference"
00082             << abort(FatalError);
00083     }
00084 
00085     return *(ptrs_[i]);
00086 }
00087 
00088 
00089 template<class T>
00090 const T* UPtrList<T>::operator()(const label i) const
00091 {
00092     return ptrs_[i];
00093 }
00094 
00095 
00096 // * * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * //
00097 
00098 template<class T>
00099 inline UPtrList<T>::iterator::iterator(T** ptr)
00100 :
00101     ptr_(ptr)
00102 {}
00103 
00104 template<class T>
00105 inline bool UPtrList<T>::iterator::operator==(const iterator& iter) const
00106 {
00107     return ptr_ == iter.ptr_;
00108 }
00109 
00110 template<class T>
00111 inline bool UPtrList<T>::iterator::operator!=(const iterator& iter) const
00112 {
00113     return ptr_ != iter.ptr_;
00114 }
00115 
00116 template<class T>
00117 inline T& UPtrList<T>::iterator::operator*()
00118 {
00119     return **ptr_;
00120 }
00121 
00122 template<class T>
00123 inline T& UPtrList<T>::iterator::operator()()
00124 {
00125     return operator*();
00126 }
00127 
00128 template<class T>
00129 inline typename UPtrList<T>::iterator
00130 UPtrList<T>::iterator::operator++()
00131 {
00132     ++ptr_;
00133     return *this;
00134 }
00135 
00136 template<class T>
00137 inline typename UPtrList<T>::iterator
00138 UPtrList<T>::iterator::operator++(int)
00139 {
00140     iterator tmp = *this;
00141     ++ptr_;
00142     return tmp;
00143 }
00144 
00145 template<class T>
00146 inline typename UPtrList<T>::iterator
00147 UPtrList<T>::iterator::operator--()
00148 {
00149     --ptr_;
00150     return *this;
00151 }
00152 
00153 template<class T>
00154 inline typename UPtrList<T>::iterator
00155 UPtrList<T>::iterator::operator--(int)
00156 {
00157     iterator tmp = *this;
00158     --ptr_;
00159     return tmp;
00160 }
00161 
00162 template<class T>
00163 inline typename UPtrList<T>::iterator
00164 UPtrList<T>::iterator::operator+=(label n)
00165 {
00166     ptr_ += n;
00167     return *this;
00168 }
00169 
00170 template<class T>
00171 inline typename UPtrList<T>::iterator
00172 operator+(const typename UPtrList<T>::iterator& iter, label n)
00173 {
00174     typename UPtrList<T>::iterator tmp = iter;
00175     return tmp += n;
00176 }
00177 
00178 template<class T>
00179 inline typename UPtrList<T>::iterator
00180 operator+(label n, const typename UPtrList<T>::iterator& iter)
00181 {
00182     typename UPtrList<T>::iterator tmp = iter;
00183     return tmp += n;
00184 }
00185 
00186 template<class T>
00187 inline typename UPtrList<T>::iterator
00188 UPtrList<T>::iterator::operator-=(label n)
00189 {
00190     ptr_ -= n;
00191     return *this;
00192 }
00193 
00194 template<class T>
00195 inline typename UPtrList<T>::iterator
00196 operator-(const typename UPtrList<T>::iterator& iter, label n)
00197 {
00198     typename UPtrList<T>::iterator tmp = iter;
00199     return tmp -= n;
00200 }
00201 
00202 template<class T>
00203 inline label operator-
00204 (
00205     const typename UPtrList<T>::iterator& iter1,
00206     const typename UPtrList<T>::iterator& iter2
00207 )
00208 {
00209     return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
00210 }
00211 
00212 template<class T>
00213 inline T& UPtrList<T>::iterator::operator[](label n)
00214 {
00215     return *(*this + n);
00216 }
00217 
00218 template<class T>
00219 inline bool UPtrList<T>::iterator::operator<(const iterator& iter) const
00220 {
00221     return ptr_ < iter.ptr_;
00222 }
00223 
00224 template<class T>
00225 inline bool UPtrList<T>::iterator::operator>(const iterator& iter) const
00226 {
00227     return ptr_ > iter.ptr_;
00228 }
00229 
00230 template<class T>
00231 inline bool UPtrList<T>::iterator::operator<=(const iterator& iter) const
00232 {
00233     return ptr_ <= iter.ptr_;
00234 }
00235 
00236 template<class T>
00237 inline bool UPtrList<T>::iterator::operator>=(const iterator& iter) const
00238 {
00239     return ptr_ >= iter.ptr_;
00240 }
00241 
00242 template<class T>
00243 inline typename UPtrList<T>::iterator UPtrList<T>::begin()
00244 {
00245     return ptrs_.begin();
00246 }
00247 
00248 template<class T>
00249 inline typename UPtrList<T>::iterator UPtrList<T>::end()
00250 {
00251     return ptrs_.end();
00252 }
00253 
00254 
00255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00256 
00257 } // End namespace Foam
00258 
00259 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd