00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::DLListBase 00026 00027 Description 00028 Base doubly-linked list. 00029 00030 SourceFiles 00031 DLListBase.C 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef DLListBase_H 00036 #define DLListBase_H 00037 00038 #include <OpenFOAM/bool.H> 00039 #include <OpenFOAM/label.H> 00040 #include <OpenFOAM/uLabel.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 true if the list is empty 00126 inline bool empty() const; 00127 00128 //- Return first entry 00129 inline link* first(); 00130 00131 //- Return const access to first entry 00132 inline const link* first() const; 00133 00134 //- Return last entry 00135 inline link* last(); 00136 00137 //- Return const access to last entry 00138 inline const link* last() const; 00139 00140 00141 // Edit 00142 00143 //- Add at head of list 00144 void insert(link*); 00145 00146 //- Add at tail of list 00147 void append(link*); 00148 00149 //- Swap this element with the one above unless it is at the top 00150 bool swapUp(link*); 00151 00152 //- Swap this element with the one below unless it is at the bottom 00153 bool swapDown(link*); 00154 00155 //- Remove and return head 00156 link* removeHead(); 00157 00158 //- Remove and return element 00159 link* remove(link*); 00160 00161 // Remove and return element specified by iterator 00162 inline link* remove(iterator&); 00163 00164 //- Replace oldLink with newLink and return element 00165 link* replace(link* oldLink, link* newLink); 00166 00167 //- Replace oldIter with newLink and return element 00168 inline link* replace(iterator& oldIter, link* newLink); 00169 00170 //- Clear the list 00171 inline void clear(); 00172 00173 //- Transfer the contents of the argument into this List 00174 // and annull the argument list. 00175 inline void transfer(DLListBase&); 00176 00177 // STL iterator 00178 00179 //- An STL-conforming iterator 00180 class iterator 00181 { 00182 friend class DLListBase; 00183 friend class const_iterator; 00184 00185 // Private data 00186 00187 //- Reference to the list this is an iterator for 00188 DLListBase& curList_; 00189 00190 //- Current element 00191 link* curElmt_; 00192 00193 //- Copy of the link 00194 link curLink_; 00195 00196 // Private Member Functions 00197 00198 //- Construct for a given SLListBase with NULL element and link. 00199 // Only used to create endIter 00200 inline iterator(DLListBase&); 00201 00202 public: 00203 00204 //- Construct for a given DLListBase and link 00205 inline iterator(DLListBase&, link*); 00206 00207 // Member operators 00208 00209 inline void operator=(const iterator&); 00210 00211 inline bool operator==(const iterator&) const; 00212 inline bool operator!=(const iterator&) const; 00213 00214 inline link& operator*(); 00215 00216 inline iterator& operator++(); 00217 inline iterator operator++(int); 00218 }; 00219 00220 inline iterator begin(); 00221 inline const iterator& end(); 00222 00223 00224 // STL const_iterator 00225 00226 //- An STL-conforming const_iterator 00227 class const_iterator 00228 { 00229 // Private data 00230 00231 //- Reference to the list this is an iterator for 00232 const DLListBase& curList_; 00233 00234 //- Current element 00235 const link* curElmt_; 00236 00237 public: 00238 00239 //- Construct for a given DLListBase and link 00240 inline const_iterator(const DLListBase&, const link*); 00241 00242 //- Construct from a non-const iterator 00243 inline const_iterator(const iterator&); 00244 00245 // Member operators 00246 00247 inline void operator=(const const_iterator&); 00248 00249 inline bool operator==(const const_iterator&) const; 00250 inline bool operator!=(const const_iterator&) const; 00251 00252 inline const link& operator*(); 00253 00254 inline const_iterator& operator++(); 00255 inline const_iterator operator++(int); 00256 }; 00257 00258 inline const_iterator cbegin() const; 00259 inline const const_iterator& cend() const; 00260 00261 inline const_iterator begin() const; 00262 inline const const_iterator& end() const; 00263 00264 private: 00265 00266 //- iterator returned by end() 00267 static iterator endIter_; 00268 00269 //- const_iterator returned by end() 00270 static const_iterator endConstIter_; 00271 00272 }; 00273 00274 00275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00276 00277 } // End namespace Foam 00278 00279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00280 00281 #include "DLListBaseI.H" 00282 00283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00284 00285 #endif 00286 00287 // ************************ vim: set sw=4 sts=4 et: ************************ //