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