OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     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 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 class Ostream;
00048 
00049 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00050 
00051 template<class LListBase, class T>
00052 class UILList;
00053 
00054 template<class LListBase, class T>
00055 Ostream& operator<<
00056 (
00057     Ostream&,
00058     const UILList<LListBase, T>&
00059 );
00060 
00061 
00062 /*---------------------------------------------------------------------------*\
00063                            Class UILList Declaration
00064 \*---------------------------------------------------------------------------*/
00065 
00066 template<class LListBase, class T>
00067 class UILList
00068 :
00069     public LListBase
00070 {
00071 
00072 public:
00073 
00074     // Forward declaration of STL iterators
00075 
00076         class iterator;
00077         friend class iterator;
00078 
00079         class const_iterator;
00080         friend class const_iterator;
00081 
00082 
00083     // Constructors
00084 
00085         //- Null construct
00086         UILList()
00087         {}
00088 
00089         //- Construct given initial T
00090         UILList(T* a)
00091         :
00092             LListBase(a)
00093         {}
00094 
00095         //- Construct as copy
00096         UILList(const UILList<LListBase, T>&);
00097 
00098 
00099     // Member Functions
00100 
00101         // Access
00102 
00103             //- Return the first entry
00104             T* first()
00105             {
00106                 return static_cast<T*>(LListBase::first());
00107             }
00108 
00109             //- Return the first entry
00110             const T* first() const
00111             {
00112                 return static_cast<const T*>(LListBase::first());
00113             }
00114 
00115             //- Return the last entry
00116             T* last()
00117             {
00118                 return static_cast<T*>(LListBase::last());
00119             }
00120 
00121             //- Return the last entry
00122             const T* last() const
00123             {
00124                 return static_cast<const T*>(LListBase::last());
00125             }
00126 
00127 
00128         // Edit
00129 
00130             //- Return and remove head
00131             T* removeHead()
00132             {
00133                 return static_cast<T*>(LListBase::removeHead());
00134             }
00135 
00136             //- Return and remove element
00137             T* remove(T* p)
00138             {
00139                 return static_cast<T*>(LListBase::remove(p));
00140             }
00141 
00142 
00143     // Member operators
00144 
00145         void operator=(const UILList<LListBase, T>&);
00146 
00147 
00148     // STL type definitions
00149 
00150         //- Type of values the DLList contains.
00151         typedef T value_type;
00152 
00153         //- Type that can be used for storing into DLList::value_type
00154         //  objects.
00155         typedef T& reference;
00156 
00157         //- Type that can be used for storing into constant
00158         //  DLList::value_type objects.
00159         typedef const T& const_reference;
00160 
00161         //- The type that can represent the size of a DLList.
00162         typedef label size_type;
00163 
00164 
00165     // STL iterator
00166 
00167         typedef typename LListBase::iterator LListBase_iterator;
00168 
00169         class iterator
00170         :
00171             public LListBase_iterator
00172         {
00173 
00174         public:
00175 
00176             //- Construct from base iterator
00177             iterator
00178             (
00179                 LListBase_iterator baseIter
00180             )
00181             :
00182                 LListBase_iterator(baseIter)
00183             {}
00184 
00185 
00186             // Member operators
00187 
00188                 T& operator*()
00189                 {
00190                     return static_cast<T&>(LListBase_iterator::operator*());
00191                 }
00192 
00193                 T& operator()()
00194                 {
00195                     return operator*();
00196                 }
00197 
00198                 iterator& operator++()
00199                 {
00200                     LListBase_iterator::operator++();
00201                     return *this;
00202                 }
00203         };
00204 
00205 
00206     // STL const_iterator
00207 
00208         typedef typename LListBase::const_iterator LListBase_const_iterator;
00209 
00210         class const_iterator
00211         :
00212             public LListBase_const_iterator
00213         {
00214 
00215         public:
00216 
00217             //- Construct from base const_iterator
00218             const_iterator
00219             (
00220                 LListBase_const_iterator baseIter
00221             )
00222             :
00223                 LListBase_const_iterator(baseIter)
00224             {}
00225 
00226             //- Construct from base iterator
00227             const_iterator
00228             (
00229                 LListBase_iterator baseIter
00230             )
00231             :
00232                 LListBase_const_iterator(baseIter)
00233             {}
00234 
00235 
00236             // Member operators
00237 
00238                 const T& operator*()
00239                 {
00240                     return 
00241                         static_cast<const T&>
00242                         (LListBase_const_iterator::operator*());
00243                 }
00244 
00245                 const T& operator()()
00246                 {
00247                     return operator*();
00248                 }
00249 
00250                 const_iterator& operator++()
00251                 {
00252                     LListBase_const_iterator::operator++();
00253                     return *this;
00254                 }
00255         };
00256 
00257 
00258     // Ostream operator
00259 
00260         friend Ostream& operator<< <LListBase, T>
00261         (
00262             Ostream&,
00263             const UILList<LListBase, T>&
00264         );
00265 };
00266 
00267 
00268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00269 
00270 } // End namespace Foam
00271 
00272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00273 
00274 #ifdef NoRepository
00275 #   include "UILList.C"
00276 #endif
00277 
00278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00279 
00280 #endif
00281 
00282 // ************************************************************************* //
For further information go to www.openfoam.org