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

SLListBase.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::SLListBase
00026 
00027 Description
00028     Base singly-linked list.
00029 
00030 SourceFiles
00031     SLListBase.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef SLListBase_H
00036 #define SLListBase_H
00037 
00038 #include <OpenFOAM/bool.H>
00039 #include <OpenFOAM/label.H>
00040 #include <OpenFOAM/uLabel.H>
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 /*---------------------------------------------------------------------------*\
00048                            Class SLListBase Declaration
00049 \*---------------------------------------------------------------------------*/
00050 
00051 class SLListBase
00052 {
00053 
00054 public:
00055 
00056     //- Link structure
00057     struct link
00058     {
00059         //- Pointer to next entry in list
00060         link* next_;
00061 
00062         //- Null construct
00063         inline link();
00064 
00065         //- Construct given pointer to another link
00066         inline link(link* p);
00067     };
00068 
00069 
00070 private:
00071 
00072     // Private data
00073 
00074        //- last_ points to last element
00075        //  last_->next_ points to first element, i.e. circular storage
00076        link* last_;
00077 
00078        //- Number of elements in in list
00079        label nElmts_;
00080 
00081     // Private member functions
00082 
00083         //- Disallow default bitwise copy construct
00084         SLListBase(const SLListBase&);
00085 
00086         //- Disallow default bitwise assignment
00087         void operator=(const SLListBase&);
00088 
00089 
00090 public:
00091 
00092     // Forward declaration of STL iterators
00093 
00094         class iterator;
00095         friend class iterator;
00096 
00097         class const_iterator;
00098         friend class const_iterator;
00099 
00100 
00101     // Constructors
00102 
00103         //- Null construct
00104         inline SLListBase();
00105 
00106         //- Construct given initial entry
00107         inline SLListBase(link*);
00108 
00109 
00110     // Destructor
00111 
00112         ~SLListBase();
00113 
00114 
00115     // Member Functions
00116 
00117         // Access
00118 
00119             //- Return number of elements in list
00120             inline label size() const;
00121 
00122             //- Return true if the list is empty
00123             inline bool empty() const;
00124 
00125             //- Return first entry
00126             inline link* first();
00127 
00128             //- Return const access to first entry
00129             inline const link* first() const;
00130 
00131             //- Return last entry
00132             inline link* last();
00133 
00134             //- Return const access to last entry
00135             inline const link* last() const;
00136 
00137 
00138         // Edit
00139 
00140             //- Add at head of list
00141             void insert(link*);
00142 
00143             //- Add at tail of list
00144             void append(link*);
00145 
00146             //- Remove and return head
00147             link* removeHead();
00148 
00149             // Remove and return element
00150             link* remove(link*);
00151 
00152             // Remove and return element specified by iterator
00153             inline link* remove(iterator&);
00154 
00155             //- Clear the list
00156             inline void clear();
00157 
00158             //- Transfer the contents of the argument into this List
00159             //  and annull the argument list.
00160             inline void transfer(SLListBase&);
00161 
00162     // STL iterator
00163 
00164         //- An STL-conforming iterator
00165         class iterator
00166         {
00167             friend class SLListBase;
00168             friend class const_iterator;
00169 
00170             // Private data
00171 
00172                 //- Reference to the list this is an iterator for
00173                 SLListBase& curList_;
00174 
00175                 //- Current element
00176                 link* curElmt_;
00177 
00178                 //- Copy of the link
00179                 link curLink_;
00180 
00181             // Private Member Functions
00182 
00183             //- Construct for a given SLListBase with NULL element and link.
00184             //  Only used to create endIter
00185             inline iterator(SLListBase&);
00186 
00187         public:
00188 
00189             //- Construct for a given SLListBase and link
00190             inline iterator(SLListBase&, link*);
00191 
00192             // Member operators
00193 
00194                 inline void operator=(const iterator&);
00195 
00196                 inline bool operator==(const iterator&) const;
00197                 inline bool operator!=(const iterator&) const;
00198 
00199                 inline link& operator*();
00200 
00201                 inline iterator& operator++();
00202                 inline iterator operator++(int);
00203         };
00204 
00205         inline iterator begin();
00206         inline const iterator& end();
00207 
00208 
00209     // STL const_iterator
00210 
00211         //- An STL-conforming const_iterator
00212         class const_iterator
00213         {
00214             // Private data
00215 
00216                 //- Reference to the list this is an iterator for
00217                 const SLListBase& curList_;
00218 
00219                 //- Current element
00220                 const link* curElmt_;
00221 
00222         public:
00223 
00224             //- Construct for a given SLListBase and link
00225             inline const_iterator(const SLListBase&, const link*);
00226 
00227             //- Construct from a non-const iterator
00228             inline const_iterator(const iterator&);
00229 
00230 
00231             // Member operators
00232 
00233                 inline void operator=(const const_iterator&);
00234 
00235                 inline bool operator==(const const_iterator&) const;
00236                 inline bool operator!=(const const_iterator&) const;
00237 
00238                 inline const link& operator*();
00239 
00240                 inline const_iterator& operator++();
00241                 inline const_iterator operator++(int);
00242         };
00243 
00244         inline const_iterator cbegin() const;
00245         inline const const_iterator& cend() const;
00246 
00247         inline const_iterator begin() const;
00248         inline const const_iterator& end() const;
00249 
00250 
00251 private:
00252 
00253         //- iterator returned by end()
00254         static iterator endIter_;
00255 
00256         //- const_iterator returned by end()
00257         static const_iterator endConstIter_;
00258 };
00259 
00260 
00261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00262 
00263 } // End namespace Foam
00264 
00265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00266 
00267 #include "SLListBaseI.H"
00268 
00269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00270 
00271 #endif
00272 
00273 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines