1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 \*---------------------------------------------------------------------------*/
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // Forward declaration of friend functions and operators
53 template<class LListBase, class T> class LList;
55 template<class LListBase, class T>
62 template<class LListBase, class T>
66 const LList<LListBase, T>&
70 /*---------------------------------------------------------------------------*\
71 Class LList Declaration
72 \*---------------------------------------------------------------------------*/
74 template<class LListBase, class T>
82 // Forward declaration of STL iterators
85 friend class iterator;
88 friend class const_iterator;
94 public LListBase::link
99 //- Construct given object
113 //- Construct given initial T
116 LListBase(new link(a))
119 //- Construct from Istream
122 //- Construct as copy
123 LList(const LList<LListBase, T>&);
135 //- Return the first entry added
138 return static_cast<link*>(LListBase::first())->obj_;
141 //- Return const access to the first entry added
142 const T& first() const
144 return static_cast<const link*>(LListBase::first())->obj_;
147 //- Return the last entry added
150 return static_cast<link*>(LListBase::last())->obj_;
153 //- Return const access to the last entry added
154 const T& last() const
156 return static_cast<const link*>(LListBase::last())->obj_;
162 //- Add at head of list
163 void insert(const T& a)
165 LListBase::insert(new link(a));
168 //- Add at tail of list
169 void append(const T& a)
171 LListBase::append(new link(a));
174 //- Remove and return head
177 link* elmtPtr = static_cast<link*>(LListBase::removeHead());
178 T data = elmtPtr->obj_;
183 //- Remove and return element
186 link* elmtPtr = static_cast<link*>(LListBase::remove(l));
187 T data = elmtPtr->obj_;
192 //- Remove and return element specified by iterator
193 T remove(iterator& it)
195 link* elmtPtr = static_cast<link*>(LListBase::remove(it));
196 T data = elmtPtr->obj_;
201 //- Delete contents of list
204 //- Transfer the contents of the argument into this List
205 // and annull the argument list.
206 void transfer(LList<LListBase, T>&);
210 void operator=(const LList<LListBase, T>&);
213 // STL type definitions
215 //- Type of values the LList contains.
216 typedef T value_type;
218 //- Type that can be used for storing into value_type
220 typedef T& reference;
222 //- Type that can be used for storing into constant
223 // LList::value_type objects.
224 typedef const T& const_reference;
226 //- The type that can represent the size of a LList.
227 typedef label size_type;
232 typedef typename LListBase::iterator LListBase_iterator;
234 //- An STL-conforming iterator
237 public LListBase_iterator
242 //- Construct from base iterator
245 LListBase_iterator baseIter
248 LListBase_iterator(baseIter)
258 (LListBase_iterator::operator*()).obj_;
266 iterator& operator++()
268 LListBase_iterator::operator++();
274 // STL const_iterator
276 typedef typename LListBase::const_iterator LListBase_const_iterator;
278 //- An STL-conforming const_iterator
281 public LListBase_const_iterator
286 //- Construct from base const_iterator
289 LListBase_const_iterator baseIter
292 LListBase_const_iterator(baseIter)
296 //- Construct from base iterator
299 LListBase_iterator baseIter
302 LListBase_const_iterator(baseIter)
311 static_cast<const link&>
312 (LListBase_const_iterator::operator*()).obj_;
315 const T& operator()()
320 const_iterator& operator++()
322 LListBase_const_iterator::operator++();
328 // IOstream operators
330 friend Istream& operator>> <LListBase, T>
336 friend Ostream& operator<< <LListBase, T>
339 const LList<LListBase, T>&
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 } // End namespace Foam
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
358 // ************************************************************************* //