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

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