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