SLListBase.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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