OpenFOAM logo
Open Source CFD Toolkit

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-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     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 template friend fuctions * * * * * * * //
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 specified from the list and delete it
00153             bool eraseHead();
00154 
00155             //- Remove the specified element from the list and delete it
00156             void clear();
00157 
00158 
00159     // Member operators
00160 
00161         //- Assign copy
00162         void operator=(const LPtrList<LListBase, T>&);
00163 
00164 
00165     // STL type definitions
00166 
00167         //- Type that can be used for storing into LPtrList::value_type
00168         //  objects.
00169         typedef T& reference;
00170 
00171         //- Type that can be used for storing into constant
00172         //  LPtrList::value_type objects.
00173         typedef T& const_reference;
00174 
00175 
00176     // STL iterator
00177 
00178         typedef typename LListBase::iterator LListBase_iterator;
00179 
00180         class iterator
00181         :
00182             public LList<LListBase, T*>::iterator
00183         {
00184 
00185         public:
00186 
00187             //- Construct from base iterator
00188             iterator
00189             (
00190                 LListBase_iterator baseIter
00191             )
00192             :
00193                 LList<LListBase, T*>::iterator(baseIter)
00194             {}
00195 
00196 
00197             // Member operators
00198 
00199                 T& operator*()
00200                 {
00201                     return *(LList<LListBase, T*>::iterator::operator*());
00202                 }
00203 
00204                 T& operator()()
00205                 {
00206                     return operator*();
00207                 }
00208         };
00209 
00210 
00211     // STL const_iterator
00212 
00213         typedef typename LListBase::const_iterator LListBase_const_iterator;
00214 
00215         class const_iterator
00216         :
00217             public LList<LListBase, T*>::const_iterator
00218         {
00219 
00220         public:
00221 
00222             //- Construct from base const_iterator
00223             const_iterator
00224             (
00225                 LListBase_const_iterator baseIter
00226             )
00227             :
00228                 LList<LListBase, T*>::const_iterator(baseIter)
00229             {}
00230 
00231             //- Construct from base iterator
00232             const_iterator
00233             (
00234                 LListBase_iterator baseIter
00235             )
00236             :
00237                 LList<LListBase, T*>::const_iterator(baseIter)
00238             {}
00239 
00240 
00241             // Member operators
00242 
00243                 const T& operator*()
00244                 {
00245                     return *(LList<LListBase, T*>::const_iterator::operator*());
00246                 }
00247 
00248                 const T& operator()()
00249                 {
00250                     return operator*();
00251                 }
00252         };
00253 
00254 
00255     // IOstream operators
00256 
00257         friend Istream& operator>> <LListBase, T>
00258         (
00259             Istream&,
00260             LPtrList<LListBase, T>&
00261         );
00262 
00263         friend Ostream& operator<< <LListBase, T>
00264         (
00265             Ostream&,
00266             const LPtrList<LListBase, T>&
00267         );
00268 };
00269 
00270 
00271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00272 
00273 } // End namespace Foam
00274 
00275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00276 
00277 #ifdef NoRepository
00278 #   include "LPtrList.C"
00279 #endif
00280 
00281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00282 
00283 #endif
00284 
00285 // ************************************************************************* //
For further information go to www.openfoam.org