OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-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     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         //- Check if the link is registered with the DLListBase
00066         inline bool registered() const;
00067 
00068         //- Deregister the link after removal
00069         inline void deregister();
00070     };
00071 
00072 
00073 private:
00074 
00075     // Private data
00076 
00077        //- first_ points to first element and last_ points to last element.
00078        link *first_, *last_;
00079 
00080        //- Number of elements in in list
00081        label nElmts_;
00082 
00083 
00084     // Private member functions
00085 
00086         //- Disallow default bitwise copy construct
00087         DLListBase(const DLListBase&);
00088 
00089         //- Disallow default bitwise assignment
00090         void operator=(const DLListBase&);
00091 
00092 
00093 public:
00094 
00095     // Forward declaration of STL iterators
00096 
00097         class iterator;
00098         friend class iterator;
00099 
00100         class const_iterator;
00101         friend class const_iterator;
00102 
00103 
00104     // Constructors
00105 
00106         //- Null construct
00107         inline DLListBase();
00108 
00109         //- Construct given initial entry
00110         inline DLListBase(link*);
00111 
00112 
00113     // Destructor
00114 
00115         ~DLListBase();
00116 
00117 
00118     // Member Functions
00119 
00120         // Access
00121 
00122             //- Return number of elements in list
00123             inline label size() 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             //- Swap this element with the one above unless it is at the top
00147             bool swapUp(link*);
00148 
00149             //- Swap this element with the one below unless it is at the bottom
00150             bool swapDown(link*);
00151 
00152             //- Remove and return head
00153             link* removeHead();
00154 
00155             //- Remove and return element
00156             link* remove(link*);
00157 
00158             // Remove and return element specified by iterator
00159             inline link* remove(iterator&);
00160 
00161             //- Clear the list
00162             inline void clear();
00163 
00164 
00165     // STL iterator
00166 
00167         class iterator
00168         {
00169             friend class DLListBase;
00170             friend class const_iterator;
00171 
00172             // Private data
00173 
00174                 //- Reference to the list this is an iterator for
00175                 DLListBase& curList_;
00176 
00177                 //- Current element
00178                 link* curElmt_;
00179 
00180                 //- Copy of the link
00181                 link curLink_;
00182 
00183         public:
00184 
00185             //- Construct for a given DLListBase and link
00186             inline iterator(DLListBase&, link*);
00187 
00188             //- Construct for a given DLListBase
00189             //  setting element and link to NULL.
00190             //  Only used to create endIter
00191             inline iterator(DLListBase&);
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 
00208         //- iterator returned by end()
00209         static iterator endIter;
00210 
00211         inline const iterator& end();
00212 
00213 
00214     // STL const_iterator
00215 
00216         class const_iterator
00217         {
00218             // Private data
00219 
00220                 //- Reference to the list this is an iterator for
00221                 const DLListBase& curList_;
00222 
00223                 //- Current element
00224                 const link* curElmt_;
00225 
00226         public:
00227 
00228             //- Construct for a given DLListBase and link
00229             inline const_iterator(const DLListBase&, const link*);
00230 
00231             //- Construct from a non-const iterator
00232             inline const_iterator(const iterator&);
00233 
00234             // Member operators
00235 
00236                 inline void operator=(const const_iterator&);
00237 
00238                 inline bool operator==(const const_iterator&) const;
00239                 inline bool operator!=(const const_iterator&) const;
00240 
00241                 inline const link& operator*();
00242 
00243                 inline const_iterator& operator++();
00244                 inline const_iterator operator++(int);
00245         };
00246 
00247         inline const_iterator begin() const;
00248 
00249         //- const_iterator returned by end()
00250         static const_iterator endConstIter;
00251 
00252         inline const const_iterator& end() const;
00253 };
00254 
00255 
00256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00257 
00258 } // End namespace Foam
00259 
00260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00261 
00262 #include "DLListBaseI.H"
00263 
00264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00265 
00266 #endif
00267 
00268 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd