OpenFOAM logo
Open Source CFD Toolkit

DLListBase.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     DLListBase
00027 
00028 Description
00029     Base doubly-linked list.
00030 
00031 SourceFiles
00032     DLListBase.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef DLListBase_H
00037 #define DLListBase_H
00038 
00039 #include "bool.H"
00040 #include "label.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 /*---------------------------------------------------------------------------*\
00048                            Class DLListBase Declaration
00049 \*---------------------------------------------------------------------------*/
00050 
00051 class DLListBase
00052 {
00053 
00054 public:
00055 
00056     //- Link structure
00057     struct link
00058     {
00059         //- Pointer to next entry in list
00060         link *prev_, *next_;
00061 
00062         //- Null construct
00063         inline link();
00064 
00065         //- Construct given pointers to previous and next links
00066         inline link(link* prev, link* next);
00067     };
00068 
00069 
00070 private:
00071 
00072     // Private data
00073 
00074        //- first_ points to first element and last_ points to last element.
00075        link *first_, *last_;
00076 
00077        //- Number of elements in in list
00078        label nElmts_;
00079 
00080     // Private member functions
00081 
00082         //- Disallow default bitwise copy construct
00083         DLListBase(const DLListBase&);
00084 
00085         //- Disallow default bitwise assignment
00086         void operator=(const DLListBase&);
00087 
00088 
00089 public:
00090 
00091     // Forward declaration of STL iterators
00092 
00093         class iterator;
00094         friend class iterator;
00095 
00096         class const_iterator;
00097         friend class const_iterator;
00098 
00099 
00100     // Constructors
00101 
00102         //- Null construct
00103         inline DLListBase();
00104 
00105         //- Construct given initial entry
00106         inline DLListBase(link*);
00107 
00108 
00109     // Destructor
00110 
00111         ~DLListBase();
00112 
00113 
00114     // Member Functions
00115 
00116         // Access
00117 
00118             //- Return number of elements in list
00119             inline label size() const;
00120 
00121             //- Return first entry
00122             inline link* first();
00123 
00124             //- Return const access to first entry
00125             inline const link* first() const;
00126 
00127             //- Return last entry
00128             inline link* last();
00129 
00130             //- Return const access to last entry
00131             inline const link* last() const;
00132 
00133 
00134         // Edit
00135 
00136             //- Add at head of list
00137             void insert(link*);
00138 
00139             //- Add at tail of list
00140             void append(link*);
00141 
00142             //- Swap this element with the one above unless it is at the top
00143             bool swapUp(link*);
00144 
00145             //- Swap this element with the one below unless it is at the bottom
00146             bool swapDown(link*);
00147 
00148             //- Remove and return head
00149             link* removeHead();
00150 
00151             //- Remove and return element
00152             link* remove(link*);
00153 
00154             //- Clear the list
00155             inline void clear();
00156 
00157 
00158     // STL iterator
00159 
00160         class iterator
00161         {
00162             friend class const_iterator;
00163 
00164             // Private data
00165 
00166                 //- Reference to the list this is an iterator for
00167                 DLListBase& curList_;
00168 
00169                 //- Current element
00170                 link* curElmt_;
00171 
00172         public:
00173 
00174             //- Construct for a given DLListBase and link
00175             inline iterator(DLListBase&, link*);
00176 
00177             // Member operators
00178 
00179                 inline void operator=(const iterator&);
00180 
00181                 inline bool operator==(const iterator&) const;
00182                 inline bool operator!=(const iterator&) const;
00183 
00184                 inline link& operator*();
00185 
00186                 inline iterator& operator++();
00187                 inline iterator operator++(int);
00188         };
00189 
00190         inline iterator begin();
00191 
00192         //- iterator returned by end()
00193         static iterator endIter;
00194 
00195         inline const iterator& end();
00196 
00197 
00198     // STL const_iterator
00199 
00200         class const_iterator
00201         {
00202             // Private data
00203 
00204                 //- Reference to the list this is an iterator for
00205                 const DLListBase& curList_;
00206 
00207                 //- Current element
00208                 const link* curElmt_;
00209 
00210         public:
00211 
00212             //- Construct for a given DLListBase and link
00213             inline const_iterator(const DLListBase&, const link*);
00214 
00215             //- Construct from a non-const iterator
00216             inline const_iterator(const iterator&);
00217 
00218             // Member operators
00219 
00220                 inline void operator=(const const_iterator&);
00221 
00222                 inline bool operator==(const const_iterator&) const;
00223                 inline bool operator!=(const const_iterator&) const;
00224 
00225                 inline const link& operator*();
00226 
00227                 inline const_iterator& operator++();
00228                 inline const_iterator operator++(int);
00229         };
00230 
00231         inline const_iterator begin() const;
00232 
00233         //- const_iterator returned by end()
00234         static const_iterator endConstIter;
00235 
00236         inline const const_iterator& end() const;
00237 };
00238 
00239 
00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00241 
00242 } // End namespace Foam
00243 
00244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00245 
00246 #include "DLListBaseI.H"
00247 
00248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00249 
00250 #endif
00251 
00252 // ************************************************************************* //
For further information go to www.openfoam.org