initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / LinkedLists / linkTypes / DLListBase / DLListBaseI.H
blobbcc20289ca39662ff82a24c2461d03264de9f715
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "error.H"
29 // * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
31 inline Foam::DLListBase::link::link()
33     prev_(0),
34     next_(0)
38 inline Foam::DLListBase::DLListBase()
40     first_(0),
41     last_(0),
42     nElmts_(0)
46 inline Foam::DLListBase::DLListBase(link* a)
48     first_(a),
49     last_(a),
50     nElmts_(1)
52     a->prev_ = a;
53     a->next_ = a;
57 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
59 inline Foam::DLListBase::~DLListBase()
63 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
65 inline bool Foam::DLListBase::link::registered() const
67     return prev_ != 0 && next_ != 0;
71 inline void Foam::DLListBase::link::deregister()
73     prev_ = 0;
74     next_ = 0;
78 inline Foam::label Foam::DLListBase::size() const
80     return nElmts_;
84 inline bool Foam::DLListBase::empty() const
86     return !nElmts_;
90 inline Foam::DLListBase::link*
91 Foam::DLListBase::first()
93     if (!nElmts_)
94     {
95         FatalErrorIn("DLListBase::first()")
96             << "list is empty"
97             << abort(FatalError);
98     }
99     return first_;
103 inline const Foam::DLListBase::link*
104 Foam::DLListBase::first() const
106     if (!nElmts_)
107     {
108         FatalErrorIn("DLListBase::first() const")
109             << "list is empty"
110             << abort(FatalError);
111     }
112     return first_;
116 inline Foam::DLListBase::link*
117 Foam::DLListBase::last()
119     if (!nElmts_)
120     {
121         FatalErrorIn("DLListBase::last()")
122             << "list is empty"
123             << abort(FatalError);
124     }
125     return last_;
129 inline const Foam::DLListBase::link*
130 Foam::DLListBase::last() const
132     if (!nElmts_)
133     {
134         FatalErrorIn("DLListBase::last() const")
135             << "list is empty"
136             << abort(FatalError);
137     }
138     return last_;
142 inline void Foam::DLListBase::clear()
144     first_ = 0;
145     last_  = 0;
146     nElmts_ = 0;
150 inline void Foam::DLListBase::transfer(DLListBase& lst)
152     first_  = lst.first_;
153     last_   = lst.last_;
154     nElmts_ = lst.nElmts_;
156     lst.clear();
160 inline Foam::DLListBase::link*
161 Foam::DLListBase::remove
163     DLListBase::iterator& it
166     return remove(it.curElmt_);
170 inline Foam::DLListBase::link*
171 Foam::DLListBase::replace
173     DLListBase::iterator& oldIter,
174     DLListBase::link* newLink
177     return replace(oldIter.curElmt_, newLink);
181 // * * * * * * * * * * * * * * * STL iterator  * * * * * * * * * * * * * * * //
183 inline Foam::DLListBase::iterator::iterator(DLListBase& s, link* elmt)
185     curList_(s),
186     curElmt_(elmt),
187     curLink_(*curElmt_)
191 inline Foam::DLListBase::iterator::iterator(DLListBase& s)
193     curList_(s),
194     curElmt_(NULL),
195     curLink_()
199 inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
201     curElmt_ = iter.curElmt_;
202     curLink_ = iter.curLink_;
206 inline bool Foam::DLListBase::iterator::operator==(const iterator& iter) const
208     return curElmt_ == iter.curElmt_;
212 inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
214     return curElmt_ != iter.curElmt_;
218 inline Foam::DLListBase::link&
219 Foam::DLListBase::iterator::operator*()
221     return *curElmt_;
225 inline Foam::DLListBase::iterator&
226 Foam::DLListBase::iterator::operator++()
228     // Check if the curElmt_ is the last element (if it points to itself)
229     // or if the list is empty because the last element may have been removed
230     if (curLink_.next_ == curElmt_ || curList_.last_ == 0)
231     {
232         curElmt_ = 0;
233     }
234     else
235     {
236         curElmt_ = curLink_.next_;
237         curLink_ = *curElmt_;
238     }
240     return *this;
244 inline Foam::DLListBase::iterator
245 Foam::DLListBase::iterator::operator++(int)
247     iterator tmp = *this;
248     ++*this;
249     return tmp;
253 inline Foam::DLListBase::iterator
254 Foam::DLListBase::begin()
256     if (size())
257     {
258         return iterator(*this, first());
259     }
260     else
261     {
262         return endIter_;
263     }
267 inline const Foam::DLListBase::iterator& Foam::DLListBase::end()
269     return endIter_;
273 // * * * * * * * * * * * * * * STL const_iterator  * * * * * * * * * * * * * //
275 inline Foam::DLListBase::const_iterator::const_iterator
277     const DLListBase& s,
278     const link* elmt
281     curList_(s),
282     curElmt_(elmt)
286 inline Foam::DLListBase::const_iterator::const_iterator(const iterator& iter)
288     curList_(iter.curList_),
289     curElmt_(iter.curElmt_)
293 inline void Foam::DLListBase::const_iterator::operator=
295     const const_iterator& iter
298     curElmt_ = iter.curElmt_;
302 inline bool Foam::DLListBase::const_iterator::operator==
304     const const_iterator& iter
305 ) const
307     return curElmt_ == iter.curElmt_;
311 inline bool Foam::DLListBase::const_iterator::operator!=
313     const const_iterator& iter
314 ) const
316     return curElmt_ != iter.curElmt_;
320 inline const Foam::DLListBase::link&
321 Foam::DLListBase::const_iterator::operator*()
323     return *curElmt_;
327 inline Foam::DLListBase::const_iterator&
328 Foam::DLListBase::const_iterator::operator++()
330     if (curElmt_ == curList_.last_)
331     {
332         curElmt_ = 0;
333     }
334     else
335     {
336         curElmt_ = curElmt_->next_;
337     }
339     return *this;
343 inline Foam::DLListBase::const_iterator
344 Foam::DLListBase::const_iterator::operator++(int)
346     const_iterator tmp = *this;
347     ++*this;
348     return tmp;
352 inline Foam::DLListBase::const_iterator
353 Foam::DLListBase::cbegin() const
355     if (size())
356     {
357         return const_iterator(*this, first());
358     }
359     else
360     {
361         return endConstIter_;
362     }
366 inline const Foam::DLListBase::const_iterator&
367 Foam::DLListBase::cend() const
369     return endConstIter_;
373 inline Foam::DLListBase::const_iterator
374 Foam::DLListBase::begin() const
376     return this->cbegin();
380 inline const Foam::DLListBase::const_iterator&
381 Foam::DLListBase::end() const
383     return endConstIter_;
387 // ************************************************************************* //