FreeFOAM The Cross-Platform CFD Toolkit
SLListBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::SLListBase
26 
27 Description
28  Base singly-linked list.
29 
30 SourceFiles
31  SLListBase.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef SLListBase_H
36 #define SLListBase_H
37 
38 #include <OpenFOAM/bool.H>
39 #include <OpenFOAM/label.H>
40 #include <OpenFOAM/uLabel.H>
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class SLListBase Declaration
49 \*---------------------------------------------------------------------------*/
50 
52 {
53 
54 public:
55 
56  //- Link structure
57  struct link
58  {
59  //- Pointer to next entry in list
61 
62  //- Null construct
63  inline link();
64 
65  //- Construct given pointer to another link
66  inline link(link* p);
67  };
68 
69 
70 private:
71 
72  // Private data
73 
74  //- last_ points to last element
75  // last_->next_ points to first element, i.e. circular storage
76  link* last_;
77 
78  //- Number of elements in in list
79  label nElmts_;
80 
81  // Private member functions
82 
83  //- Disallow default bitwise copy construct
84  SLListBase(const SLListBase&);
85 
86  //- Disallow default bitwise assignment
87  void operator=(const SLListBase&);
88 
89 
90 public:
91 
92  // Forward declaration of STL iterators
93 
94  class iterator;
95  friend class iterator;
96 
98  friend class const_iterator;
99 
100 
101  // Constructors
102 
103  //- Null construct
104  inline SLListBase();
105 
106  //- Construct given initial entry
107  inline SLListBase(link*);
108 
109 
110  // Destructor
111 
112  ~SLListBase();
113 
114 
115  // Member Functions
116 
117  // Access
118 
119  //- Return number of elements in list
120  inline label size() const;
121 
122  //- Return true if the list is empty
123  inline bool empty() const;
124 
125  //- Return first entry
126  inline link* first();
127 
128  //- Return const access to first entry
129  inline const link* first() const;
130 
131  //- Return last entry
132  inline link* last();
133 
134  //- Return const access to last entry
135  inline const link* last() const;
136 
137 
138  // Edit
139 
140  //- Add at head of list
141  void insert(link*);
142 
143  //- Add at tail of list
144  void append(link*);
145 
146  //- Remove and return head
147  link* removeHead();
148 
149  // Remove and return element
150  link* remove(link*);
151 
152  // Remove and return element specified by iterator
153  inline link* remove(iterator&);
154 
155  //- Clear the list
156  inline void clear();
157 
158  //- Transfer the contents of the argument into this List
159  // and annull the argument list.
160  inline void transfer(SLListBase&);
161 
162  // STL iterator
163 
164  //- An STL-conforming iterator
165  class iterator
166  {
167  friend class SLListBase;
168  friend class const_iterator;
169 
170  // Private data
171 
172  //- Reference to the list this is an iterator for
173  SLListBase& curList_;
174 
175  //- Current element
176  link* curElmt_;
177 
178  //- Copy of the link
179  link curLink_;
180 
181  // Private Member Functions
182 
183  //- Construct for a given SLListBase with NULL element and link.
184  // Only used to create endIter
185  inline iterator(SLListBase&);
186 
187  public:
188 
189  //- Construct for a given SLListBase and link
190  inline iterator(SLListBase&, link*);
191 
192  // Member operators
193 
194  inline void operator=(const iterator&);
195 
196  inline bool operator==(const iterator&) const;
197  inline bool operator!=(const iterator&) const;
198 
199  inline link& operator*();
200 
201  inline iterator& operator++();
202  inline iterator operator++(int);
203  };
204 
205  inline iterator begin();
206  inline const iterator& end();
207 
208 
209  // STL const_iterator
210 
211  //- An STL-conforming const_iterator
213  {
214  // Private data
215 
216  //- Reference to the list this is an iterator for
217  const SLListBase& curList_;
218 
219  //- Current element
220  const link* curElmt_;
221 
222  public:
223 
224  //- Construct for a given SLListBase and link
225  inline const_iterator(const SLListBase&, const link*);
226 
227  //- Construct from a non-const iterator
228  inline const_iterator(const iterator&);
229 
230 
231  // Member operators
232 
233  inline void operator=(const const_iterator&);
234 
235  inline bool operator==(const const_iterator&) const;
236  inline bool operator!=(const const_iterator&) const;
237 
238  inline const link& operator*();
239 
240  inline const_iterator& operator++();
241  inline const_iterator operator++(int);
242  };
243 
244  inline const_iterator cbegin() const;
245  inline const const_iterator& cend() const;
246 
247  inline const_iterator begin() const;
248  inline const const_iterator& end() const;
249 
250 
251 private:
252 
253  //- iterator returned by end()
254  static iterator endIter_;
255 
256  //- const_iterator returned by end()
257  static const_iterator endConstIter_;
258 };
259 
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 } // End namespace Foam
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #include "SLListBaseI.H"
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #endif
272 
273 // ************************ vim: set sw=4 sts=4 et: ************************ //