1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
29 Template class for non-intrusive linked lists.
35 \*---------------------------------------------------------------------------*/
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // Forward declaration of friend functions and operators
52 template<class LListBase, class T> class LList;
54 template<class LListBase, class T>
61 template<class LListBase, class T>
65 const LList<LListBase, T>&
69 /*---------------------------------------------------------------------------*\
70 Class LList Declaration
71 \*---------------------------------------------------------------------------*/
73 template<class LListBase, class T>
81 // Forward declaration of STL iterators
84 friend class iterator;
87 friend class const_iterator;
93 public LListBase::link
98 //- Construct given object
112 //- Construct given initial T
115 LListBase(new link(a))
118 //- Construct from Istream
121 //- Construct as copy
122 LList(const LList<LListBase, T>&);
134 //- Return the first entry added
137 return static_cast<link*>(LListBase::first())->obj_;
140 //- Return const access to the first entry added
141 const T& first() const
143 return static_cast<const link*>(LListBase::first())->obj_;
146 //- Return the last entry added
149 return static_cast<link*>(LListBase::last())->obj_;
152 //- Return const access to the last entry added
153 const T& last() const
155 return static_cast<const link*>(LListBase::last())->obj_;
161 //- Add at head of list
162 void insert(const T& a)
164 LListBase::insert(new link(a));
167 //- Add at tail of list
168 void append(const T& a)
170 LListBase::append(new link(a));
173 //- Remove and return head
176 link* elmtPtr = static_cast<link*>(LListBase::removeHead());
177 T data = elmtPtr->obj_;
182 //- Remove and return element
185 link* elmtPtr = static_cast<link*>(LListBase::remove(l));
186 T data = elmtPtr->obj_;
191 //- Remove and return element specified by iterator
192 T remove(iterator& it)
194 link* elmtPtr = static_cast<link*>(LListBase::remove(it));
195 T data = elmtPtr->obj_;
200 //- Delete contents of list
206 void operator=(const LList<LListBase, T>&);
209 // STL type definitions
211 //- Type of values the LList contains.
212 typedef T value_type;
214 //- Type that can be used for storing into value_type
216 typedef T& reference;
218 //- Type that can be used for storing into constant
219 // LList::value_type objects.
220 typedef const T& const_reference;
222 //- The type that can represent the size of a LList.
223 typedef label size_type;
228 typedef typename LListBase::iterator LListBase_iterator;
230 //- An STL-conforming iterator
233 public LListBase_iterator
238 //- Construct from base iterator
241 LListBase_iterator baseIter
244 LListBase_iterator(baseIter)
254 (LListBase_iterator::operator*()).obj_;
262 iterator& operator++()
264 LListBase_iterator::operator++();
270 // STL const_iterator
272 typedef typename LListBase::const_iterator LListBase_const_iterator;
274 //- An STL-conforming const_iterator
277 public LListBase_const_iterator
282 //- Construct from base const_iterator
285 LListBase_const_iterator baseIter
288 LListBase_const_iterator(baseIter)
292 //- Construct from base iterator
295 LListBase_iterator baseIter
298 LListBase_const_iterator(baseIter)
307 static_cast<const link&>
308 (LListBase_const_iterator::operator*()).obj_;
311 const T& operator()()
316 const_iterator& operator++()
318 LListBase_const_iterator::operator++();
324 // IOstream operators
326 friend Istream& operator>>
335 friend Ostream& operator<<
341 const LList<LListBase, T>&
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 } // End namespace Foam
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 // ************************************************************************* //