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