FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::UILList
00026 
00027 Description
00028     Template class for intrusive linked lists.
00029 
00030 SourceFiles
00031     UILList.C
00032     UILListIO.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef UILList_H
00037 #define UILList_H
00038 
00039 #include <OpenFOAM/label.H>
00040 #include <OpenFOAM/uLabel.H>
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 class Ostream;
00048 
00049 // Forward declaration of friend functions and operators
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             //- Remove and return head
00131             T* removeHead()
00132             {
00133                 return static_cast<T*>(LListBase::removeHead());
00134             }
00135 
00136             //- Remove and return element
00137             T* remove(T* p)
00138             {
00139                 return static_cast<T*>(LListBase::remove(p));
00140             }
00141 
00142             //- Remove and return specified by iterator
00143             T* remove(iterator& it)
00144             {
00145                 return static_cast<T*>(LListBase::remove(it));
00146             }
00147 
00148 
00149     // Member operators
00150 
00151         void operator=(const UILList<LListBase, T>&);
00152 
00153 
00154     // STL type definitions
00155 
00156         //- Type of values the DLList contains.
00157         typedef T value_type;
00158 
00159         //- Type that can be used for storing into DLList::value_type
00160         //  objects.
00161         typedef T& reference;
00162 
00163         //- Type that can be used for storing into constant
00164         //  DLList::value_type objects.
00165         typedef const T& const_reference;
00166 
00167         //- The type that can represent the size of a DLList.
00168         typedef label size_type;
00169 
00170 
00171     // STL iterator
00172 
00173         typedef typename LListBase::iterator LListBase_iterator;
00174 
00175         //- An STL-conforming iterator
00176         class iterator
00177         :
00178             public LListBase_iterator
00179         {
00180 
00181         public:
00182 
00183             //- Construct from base iterator
00184             iterator
00185             (
00186                 LListBase_iterator baseIter
00187             )
00188             :
00189                 LListBase_iterator(baseIter)
00190             {}
00191 
00192 
00193             // Member operators
00194 
00195                 T& operator*()
00196                 {
00197                     return static_cast<T&>(LListBase_iterator::operator*());
00198                 }
00199 
00200                 T& operator()()
00201                 {
00202                     return operator*();
00203                 }
00204 
00205                 iterator& operator++()
00206                 {
00207                     LListBase_iterator::operator++();
00208                     return *this;
00209                 }
00210         };
00211 
00212 
00213     // STL const_iterator
00214 
00215         typedef typename LListBase::const_iterator LListBase_const_iterator;
00216 
00217         //- An STL-conforming const_iterator
00218         class const_iterator
00219         :
00220             public LListBase_const_iterator
00221         {
00222 
00223         public:
00224 
00225             //- Construct from base const_iterator
00226             const_iterator
00227             (
00228                 LListBase_const_iterator baseIter
00229             )
00230             :
00231                 LListBase_const_iterator(baseIter)
00232             {}
00233 
00234             //- Construct from base iterator
00235             const_iterator
00236             (
00237                 LListBase_iterator baseIter
00238             )
00239             :
00240                 LListBase_const_iterator(baseIter)
00241             {}
00242 
00243 
00244             // Member operators
00245 
00246                 const T& operator*()
00247                 {
00248                     return
00249                         static_cast<const T&>
00250                         (LListBase_const_iterator::operator*());
00251                 }
00252 
00253                 const T& operator()()
00254                 {
00255                     return operator*();
00256                 }
00257 
00258                 const_iterator& operator++()
00259                 {
00260                     LListBase_const_iterator::operator++();
00261                     return *this;
00262                 }
00263         };
00264 
00265 
00266     // STL member operators
00267 
00268         //- Equality operation on ULists of the same type.
00269         //  Returns true when the ULists are element-wise equal
00270         //  (using UList::value_type::operator==).  Takes linear time.
00271         bool operator==(const UILList<LListBase, T>&) const;
00272 
00273         //- The opposite of the equality operation. Takes linear time.
00274         bool operator!=(const UILList<LListBase, T>&) const;
00275 
00276 
00277     // Ostream operator
00278 
00279         friend Ostream& operator<< <LListBase, T>
00280         (
00281             Ostream&,
00282             const UILList<LListBase, T>&
00283         );
00284 };
00285 
00286 
00287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00288 
00289 } // End namespace Foam
00290 
00291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00292 
00293 #ifdef NoRepository
00294 #   include "UILList.C"
00295 #endif
00296 
00297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00298 
00299 #endif
00300 
00301 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines