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