DLListBaseI.H
Go to the documentation of this file.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
00030
00031 inline Foam::DLListBase::link::link()
00032 :
00033 prev_(0),
00034 next_(0)
00035 {}
00036
00037
00038 inline Foam::DLListBase::DLListBase()
00039 :
00040 first_(0),
00041 last_(0),
00042 nElmts_(0)
00043 {}
00044
00045
00046 inline Foam::DLListBase::DLListBase(link* a)
00047 :
00048 first_(a),
00049 last_(a),
00050 nElmts_(1)
00051 {
00052 a->prev_ = a;
00053 a->next_ = a;
00054 }
00055
00056
00057
00058
00059 inline Foam::DLListBase::~DLListBase()
00060 {}
00061
00062
00063
00064
00065 inline bool Foam::DLListBase::link::registered() const
00066 {
00067 return prev_ != 0 && next_ != 0;
00068 }
00069
00070
00071 inline void Foam::DLListBase::link::deregister()
00072 {
00073 prev_ = 0;
00074 next_ = 0;
00075 }
00076
00077
00078 inline Foam::label Foam::DLListBase::size() const
00079 {
00080 return nElmts_;
00081 }
00082
00083
00084 inline bool Foam::DLListBase::empty() const
00085 {
00086 return !nElmts_;
00087 }
00088
00089
00090 inline Foam::DLListBase::link*
00091 Foam::DLListBase::first()
00092 {
00093 if (!nElmts_)
00094 {
00095 FatalErrorIn("DLListBase::first()")
00096 << "list is empty"
00097 << abort(FatalError);
00098 }
00099 return first_;
00100 }
00101
00102
00103 inline const Foam::DLListBase::link*
00104 Foam::DLListBase::first() const
00105 {
00106 if (!nElmts_)
00107 {
00108 FatalErrorIn("DLListBase::first() const")
00109 << "list is empty"
00110 << abort(FatalError);
00111 }
00112 return first_;
00113 }
00114
00115
00116 inline Foam::DLListBase::link*
00117 Foam::DLListBase::last()
00118 {
00119 if (!nElmts_)
00120 {
00121 FatalErrorIn("DLListBase::last()")
00122 << "list is empty"
00123 << abort(FatalError);
00124 }
00125 return last_;
00126 }
00127
00128
00129 inline const Foam::DLListBase::link*
00130 Foam::DLListBase::last() const
00131 {
00132 if (!nElmts_)
00133 {
00134 FatalErrorIn("DLListBase::last() const")
00135 << "list is empty"
00136 << abort(FatalError);
00137 }
00138 return last_;
00139 }
00140
00141
00142 inline void Foam::DLListBase::clear()
00143 {
00144 first_ = 0;
00145 last_ = 0;
00146 nElmts_ = 0;
00147 }
00148
00149
00150 inline void Foam::DLListBase::transfer(DLListBase& lst)
00151 {
00152 first_ = lst.first_;
00153 last_ = lst.last_;
00154 nElmts_ = lst.nElmts_;
00155
00156 lst.clear();
00157 }
00158
00159
00160 inline Foam::DLListBase::link*
00161 Foam::DLListBase::remove
00162 (
00163 DLListBase::iterator& it
00164 )
00165 {
00166 return remove(it.curElmt_);
00167 }
00168
00169
00170 inline Foam::DLListBase::link*
00171 Foam::DLListBase::replace
00172 (
00173 DLListBase::iterator& oldIter,
00174 DLListBase::link* newLink
00175 )
00176 {
00177 return replace(oldIter.curElmt_, newLink);
00178 }
00179
00180
00181
00182
00183 inline Foam::DLListBase::iterator::iterator(DLListBase& s, link* elmt)
00184 :
00185 curList_(s),
00186 curElmt_(elmt),
00187 curLink_(*curElmt_)
00188 {}
00189
00190
00191 inline Foam::DLListBase::iterator::iterator(DLListBase& s)
00192 :
00193 curList_(s),
00194 curElmt_(NULL),
00195 curLink_()
00196 {}
00197
00198
00199 inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
00200 {
00201 curElmt_ = iter.curElmt_;
00202 curLink_ = iter.curLink_;
00203 }
00204
00205
00206 inline bool Foam::DLListBase::iterator::operator==(const iterator& iter) const
00207 {
00208 return curElmt_ == iter.curElmt_;
00209 }
00210
00211
00212 inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
00213 {
00214 return curElmt_ != iter.curElmt_;
00215 }
00216
00217
00218 inline Foam::DLListBase::link&
00219 Foam::DLListBase::iterator::operator*()
00220 {
00221 return *curElmt_;
00222 }
00223
00224
00225 inline Foam::DLListBase::iterator&
00226 Foam::DLListBase::iterator::operator++()
00227 {
00228
00229
00230 if (curLink_.next_ == curElmt_ || curList_.last_ == 0)
00231 {
00232 curElmt_ = 0;
00233 }
00234 else
00235 {
00236 curElmt_ = curLink_.next_;
00237 curLink_ = *curElmt_;
00238 }
00239
00240 return *this;
00241 }
00242
00243
00244 inline Foam::DLListBase::iterator
00245 Foam::DLListBase::iterator::operator++(int)
00246 {
00247 iterator tmp = *this;
00248 ++*this;
00249 return tmp;
00250 }
00251
00252
00253 inline Foam::DLListBase::iterator
00254 Foam::DLListBase::begin()
00255 {
00256 if (size())
00257 {
00258 return iterator(*this, first());
00259 }
00260 else
00261 {
00262 return endIter_;
00263 }
00264 }
00265
00266
00267 inline const Foam::DLListBase::iterator& Foam::DLListBase::end()
00268 {
00269 return endIter_;
00270 }
00271
00272
00273
00274
00275 inline Foam::DLListBase::const_iterator::const_iterator
00276 (
00277 const DLListBase& s,
00278 const link* elmt
00279 )
00280 :
00281 curList_(s),
00282 curElmt_(elmt)
00283 {}
00284
00285
00286 inline Foam::DLListBase::const_iterator::const_iterator(const iterator& iter)
00287 :
00288 curList_(iter.curList_),
00289 curElmt_(iter.curElmt_)
00290 {}
00291
00292
00293 inline void Foam::DLListBase::const_iterator::operator=
00294 (
00295 const const_iterator& iter
00296 )
00297 {
00298 curElmt_ = iter.curElmt_;
00299 }
00300
00301
00302 inline bool Foam::DLListBase::const_iterator::operator==
00303 (
00304 const const_iterator& iter
00305 ) const
00306 {
00307 return curElmt_ == iter.curElmt_;
00308 }
00309
00310
00311 inline bool Foam::DLListBase::const_iterator::operator!=
00312 (
00313 const const_iterator& iter
00314 ) const
00315 {
00316 return curElmt_ != iter.curElmt_;
00317 }
00318
00319
00320 inline const Foam::DLListBase::link&
00321 Foam::DLListBase::const_iterator::operator*()
00322 {
00323 return *curElmt_;
00324 }
00325
00326
00327 inline Foam::DLListBase::const_iterator&
00328 Foam::DLListBase::const_iterator::operator++()
00329 {
00330 if (curElmt_ == curList_.last_)
00331 {
00332 curElmt_ = 0;
00333 }
00334 else
00335 {
00336 curElmt_ = curElmt_->next_;
00337 }
00338
00339 return *this;
00340 }
00341
00342
00343 inline Foam::DLListBase::const_iterator
00344 Foam::DLListBase::const_iterator::operator++(int)
00345 {
00346 const_iterator tmp = *this;
00347 ++*this;
00348 return tmp;
00349 }
00350
00351
00352 inline Foam::DLListBase::const_iterator
00353 Foam::DLListBase::cbegin() const
00354 {
00355 if (size())
00356 {
00357 return const_iterator(*this, first());
00358 }
00359 else
00360 {
00361 return endConstIter_;
00362 }
00363 }
00364
00365
00366 inline const Foam::DLListBase::const_iterator&
00367 Foam::DLListBase::cend() const
00368 {
00369 return endConstIter_;
00370 }
00371
00372
00373 inline Foam::DLListBase::const_iterator
00374 Foam::DLListBase::begin() const
00375 {
00376 return this->cbegin();
00377 }
00378
00379
00380 inline const Foam::DLListBase::const_iterator&
00381 Foam::DLListBase::end() const
00382 {
00383 return endConstIter_;
00384 }
00385
00386
00387
Copyright © 2000-2009 OpenCFD Ltd