FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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