OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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