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

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