OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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     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 
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 first entry
00123             inline link* first();
00124 
00125             //- Return const access to first entry
00126             inline const link* first() const;
00127 
00128             //- Return last entry
00129             inline link* last();
00130 
00131             //- Return const access to last entry
00132             inline const link* last() const;
00133 
00134 
00135         // Edit
00136 
00137             //- Add at head of list
00138             void insert(link*);
00139 
00140             //- Add at tail of list
00141             void append(link*);
00142 
00143             //- Remove and return head
00144             link* removeHead();
00145 
00146             // Remove and return element
00147             link* remove(link*);
00148 
00149             // Remove and return element specified by iterator
00150             inline link* remove(iterator&);
00151 
00152             //- Clear the list
00153             inline void clear();
00154 
00155 
00156     // STL iterator
00157 
00158         class iterator
00159         {
00160             friend class SLListBase;
00161             friend class const_iterator;
00162 
00163             // Private data
00164 
00165                 //- Reference to the list this is an iterator for
00166                 SLListBase& curList_;
00167 
00168                 //- Current element
00169                 link* curElmt_;
00170 
00171                 //- Copy of the link
00172                 link curLink_;
00173 
00174         public:
00175 
00176             //- Construct for a given SLListBase and link
00177             inline iterator(SLListBase&, link*);
00178 
00179             //- Construct for a given SLListBase
00180             //  setting element and link to NULL.
00181             //  Only used to create endIter
00182             inline iterator(SLListBase&);
00183 
00184 
00185             // Member operators
00186 
00187                 inline void operator=(const iterator&);
00188 
00189                 inline bool operator==(const iterator&) const;
00190                 inline bool operator!=(const iterator&) const;
00191 
00192                 inline link& operator*();
00193 
00194                 inline iterator& operator++();
00195                 inline iterator operator++(int);
00196         };
00197 
00198         inline iterator begin();
00199 
00200         //- iterator returned by end()
00201         static iterator endIter;
00202 
00203         inline const iterator& end();
00204 
00205 
00206     // STL const_iterator
00207 
00208         class const_iterator
00209         {
00210             // Private data
00211 
00212                 //- Reference to the list this is an iterator for
00213                 const SLListBase& curList_;
00214 
00215                 //- Current element
00216                 const link* curElmt_;
00217 
00218         public:
00219 
00220             //- Construct for a given SLListBase and link
00221             inline const_iterator(const SLListBase&, const link*);
00222 
00223             //- Construct from a non-const iterator
00224             inline const_iterator(const iterator&);
00225 
00226 
00227             // Member operators
00228 
00229                 inline void operator=(const const_iterator&);
00230 
00231                 inline bool operator==(const const_iterator&) const;
00232                 inline bool operator!=(const const_iterator&) const;
00233 
00234                 inline const link& operator*();
00235 
00236                 inline const_iterator& operator++();
00237                 inline const_iterator operator++(int);
00238         };
00239 
00240         inline const_iterator begin() const;
00241 
00242         //- const_iterator returned by end()
00243         static const_iterator endConstIter;
00244 
00245         inline const const_iterator& end() const;
00246 };
00247 
00248 
00249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00250 
00251 } // End namespace Foam
00252 
00253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00254 
00255 #include "SLListBaseI.H"
00256 
00257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00258 
00259 #endif
00260 
00261 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd