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

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