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

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