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

UILList.H

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 Class
00026     Foam::UILList
00027 
00028 Description
00029     Template class for intrusive linked lists.
00030 
00031 SourceFiles
00032     UILList.C
00033     UILListIO.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef UILList_H
00038 #define UILList_H
00039 
00040 #include "label.H"
00041 #include "uLabel.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 class Ostream;
00049 
00050 // Forward declaration of friend functions and operators
00051 
00052 template<class LListBase, class T>
00053 class UILList;
00054 
00055 template<class LListBase, class T>
00056 Ostream& operator<<
00057 (
00058     Ostream&,
00059     const UILList<LListBase, T>&
00060 );
00061 
00062 
00063 /*---------------------------------------------------------------------------*\
00064                            Class UILList Declaration
00065 \*---------------------------------------------------------------------------*/
00066 
00067 template<class LListBase, class T>
00068 class UILList
00069 :
00070     public LListBase
00071 {
00072 
00073 public:
00074 
00075     // Forward declaration of STL iterators
00076 
00077         class iterator;
00078         friend class iterator;
00079 
00080         class const_iterator;
00081         friend class const_iterator;
00082 
00083 
00084     // Constructors
00085 
00086         //- Null construct
00087         UILList()
00088         {}
00089 
00090         //- Construct given initial T
00091         UILList(T* a)
00092         :
00093             LListBase(a)
00094         {}
00095 
00096         //- Construct as copy
00097         UILList(const UILList<LListBase, T>&);
00098 
00099 
00100     // Member Functions
00101 
00102         // Access
00103 
00104             //- Return the first entry
00105             T* first()
00106             {
00107                 return static_cast<T*>(LListBase::first());
00108             }
00109 
00110             //- Return the first entry
00111             const T* first() const
00112             {
00113                 return static_cast<const T*>(LListBase::first());
00114             }
00115 
00116             //- Return the last entry
00117             T* last()
00118             {
00119                 return static_cast<T*>(LListBase::last());
00120             }
00121 
00122             //- Return the last entry
00123             const T* last() const
00124             {
00125                 return static_cast<const T*>(LListBase::last());
00126             }
00127 
00128 
00129         // Edit
00130 
00131             //- Remove and return head
00132             T* removeHead()
00133             {
00134                 return static_cast<T*>(LListBase::removeHead());
00135             }
00136 
00137             //- Remove and return element
00138             T* remove(T* p)
00139             {
00140                 return static_cast<T*>(LListBase::remove(p));
00141             }
00142 
00143             //- Remove and return specified by iterator
00144             T* remove(iterator& it)
00145             {
00146                 return static_cast<T*>(LListBase::remove(it));
00147             }
00148 
00149 
00150     // Member operators
00151 
00152         void operator=(const UILList<LListBase, T>&);
00153 
00154 
00155     // STL type definitions
00156 
00157         //- Type of values the DLList contains.
00158         typedef T value_type;
00159 
00160         //- Type that can be used for storing into DLList::value_type
00161         //  objects.
00162         typedef T& reference;
00163 
00164         //- Type that can be used for storing into constant
00165         //  DLList::value_type objects.
00166         typedef const T& const_reference;
00167 
00168         //- The type that can represent the size of a DLList.
00169         typedef label size_type;
00170 
00171 
00172     // STL iterator
00173 
00174         typedef typename LListBase::iterator LListBase_iterator;
00175 
00176         //- An STL-conforming iterator
00177         class iterator
00178         :
00179             public LListBase_iterator
00180         {
00181 
00182         public:
00183 
00184             //- Construct from base iterator
00185             iterator
00186             (
00187                 LListBase_iterator baseIter
00188             )
00189             :
00190                 LListBase_iterator(baseIter)
00191             {}
00192 
00193 
00194             // Member operators
00195 
00196                 T& operator*()
00197                 {
00198                     return static_cast<T&>(LListBase_iterator::operator*());
00199                 }
00200 
00201                 T& operator()()
00202                 {
00203                     return operator*();
00204                 }
00205 
00206                 iterator& operator++()
00207                 {
00208                     LListBase_iterator::operator++();
00209                     return *this;
00210                 }
00211         };
00212 
00213 
00214     // STL const_iterator
00215 
00216         typedef typename LListBase::const_iterator LListBase_const_iterator;
00217 
00218         //- An STL-conforming const_iterator
00219         class const_iterator
00220         :
00221             public LListBase_const_iterator
00222         {
00223 
00224         public:
00225 
00226             //- Construct from base const_iterator
00227             const_iterator
00228             (
00229                 LListBase_const_iterator baseIter
00230             )
00231             :
00232                 LListBase_const_iterator(baseIter)
00233             {}
00234 
00235             //- Construct from base iterator
00236             const_iterator
00237             (
00238                 LListBase_iterator baseIter
00239             )
00240             :
00241                 LListBase_const_iterator(baseIter)
00242             {}
00243 
00244 
00245             // Member operators
00246 
00247                 const T& operator*()
00248                 {
00249                     return
00250                         static_cast<const T&>
00251                         (LListBase_const_iterator::operator*());
00252                 }
00253 
00254                 const T& operator()()
00255                 {
00256                     return operator*();
00257                 }
00258 
00259                 const_iterator& operator++()
00260                 {
00261                     LListBase_const_iterator::operator++();
00262                     return *this;
00263                 }
00264         };
00265 
00266 
00267     // STL member operators
00268 
00269         //- Equality operation on ULists of the same type.
00270         //  Returns true when the ULists are element-wise equal
00271         //  (using UList::value_type::operator==).  Takes linear time.
00272         bool operator==(const UILList<LListBase, T>&) const;
00273 
00274         //- The opposite of the equality operation. Takes linear time.
00275         bool operator!=(const UILList<LListBase, T>&) const;
00276 
00277 
00278     // Ostream operator
00279 
00280         friend Ostream& operator<< <LListBase, T>
00281         (
00282             Ostream&,
00283             const UILList<LListBase, T>&
00284         );
00285 };
00286 
00287 
00288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00289 
00290 } // End namespace Foam
00291 
00292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00293 
00294 #ifdef NoRepository
00295 #   include "UILList.C"
00296 #endif
00297 
00298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00299 
00300 #endif
00301 
00302 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd