![]() |
|
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 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 //- Clear the list 00150 inline void clear(); 00151 00152 00153 // STL iterator 00154 00155 class iterator 00156 { 00157 friend class const_iterator; 00158 00159 // Private data 00160 00161 //- Reference to the list this is an iterator for 00162 SLListBase& curList_; 00163 00164 //- Current element 00165 link* curElmt_; 00166 00167 public: 00168 00169 //- Construct for a given SLListBase and link 00170 inline iterator(SLListBase&, link*); 00171 00172 // Member operators 00173 00174 inline void operator=(const iterator&); 00175 00176 inline bool operator==(const iterator&) const; 00177 inline bool operator!=(const iterator&) const; 00178 00179 inline link& operator*(); 00180 00181 inline iterator& operator++(); 00182 inline iterator operator++(int); 00183 }; 00184 00185 inline iterator begin(); 00186 00187 //- iterator returned by end() 00188 static iterator endIter; 00189 00190 inline const iterator& end(); 00191 00192 00193 // STL const_iterator 00194 00195 class const_iterator 00196 { 00197 // Private data 00198 00199 //- Reference to the list this is an iterator for 00200 const SLListBase& curList_; 00201 00202 //- Current element 00203 const link* curElmt_; 00204 00205 public: 00206 00207 //- Construct for a given SLListBase and link 00208 inline const_iterator(const SLListBase&, const link*); 00209 00210 //- Construct from a non-const iterator 00211 inline const_iterator(const iterator&); 00212 00213 00214 // Member operators 00215 00216 inline void operator=(const const_iterator&); 00217 00218 inline bool operator==(const const_iterator&) const; 00219 inline bool operator!=(const const_iterator&) const; 00220 00221 inline const link& operator*(); 00222 00223 inline const_iterator& operator++(); 00224 inline const_iterator operator++(int); 00225 }; 00226 00227 inline const_iterator begin() const; 00228 00229 //- const_iterator returned by end() 00230 static const_iterator endConstIter; 00231 00232 inline const const_iterator& end() const; 00233 }; 00234 00235 00236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00237 00238 } // End namespace Foam 00239 00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00241 00242 #include "SLListBaseI.H" 00243 00244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00245 00246 #endif 00247 00248 // ************************************************************************* //