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

SLListBase.C

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 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/error.H>
00027 #include "SLListBase.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 Foam::SLListBase::iterator Foam::SLListBase::endIter_
00032 (
00033     const_cast<SLListBase&>(static_cast<const SLListBase&>(SLListBase()))
00034 );
00035 
00036 Foam::SLListBase::const_iterator Foam::SLListBase::endConstIter_
00037 (
00038     static_cast<const SLListBase&>(SLListBase()),
00039     reinterpret_cast<const link*>(0)
00040 );
00041 
00042 
00043 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00044 
00045 void Foam::SLListBase::insert(SLListBase::link* a)
00046 {
00047     nElmts_++;
00048 
00049     if (last_)
00050     {
00051         a->next_ = last_->next_;
00052     }
00053     else
00054     {
00055         last_ = a;
00056     }
00057 
00058     last_->next_ = a;
00059 }
00060 
00061 
00062 void Foam::SLListBase::append(SLListBase::link* a)
00063 {
00064     nElmts_++;
00065 
00066     if (last_)
00067     {
00068         a->next_ = last_->next_;
00069         last_ = last_->next_ = a;
00070     }
00071     else
00072     {
00073         last_ = a->next_ = a;
00074     }
00075 }
00076 
00077 
00078 Foam::SLListBase::link* Foam::SLListBase::removeHead()
00079 {
00080     nElmts_--;
00081 
00082     if (last_ == 0)
00083     {
00084         FatalErrorIn("SLListBase::remove()")
00085             << "remove from empty list"
00086             << abort(FatalError);
00087     }
00088 
00089     SLListBase::link* f = last_->next_;
00090 
00091     if (f == last_)
00092     {
00093         last_ = 0;
00094     }
00095     else
00096     {
00097         last_->next_ = f->next_;
00098     }
00099 
00100     return f;
00101 }
00102 
00103 
00104 Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
00105 {
00106     SLListBase::iterator iter = begin();
00107     SLListBase::link *prev = &(*iter);
00108 
00109     if (it == prev)
00110     {
00111         return removeHead();
00112     }
00113 
00114     nElmts_--;
00115 
00116     for (++iter; iter != end(); ++iter)
00117     {
00118         SLListBase::link *p = &(*iter);
00119 
00120         if (p == it)
00121         {
00122             prev->next_ = p->next_;
00123 
00124             if (p == last_)
00125             {
00126                 last_ = prev;
00127             }
00128 
00129             return it;
00130         }
00131 
00132         prev = p;
00133     }
00134 
00135     return 0;
00136 }
00137 
00138 
00139 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines