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) 2011-2015 OpenFOAM Foundation
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 "bool.H"
39 #include "label.H"
40 #include "uLabel.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class SLListBase Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class SLListBase
52 {
53 
54 public:
55 
56  //- Link structure
57  struct link
58  {
59  //- Pointer to next entry in list
60  link* next_;
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 
97  class const_iterator;
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  ~SLListBase();
112 
113 
114  // Member Functions
115 
116  // Access
117 
118  //- Return number of elements in list
119  inline label size() const;
120 
121  //- Return true if the list is empty
122  inline bool empty() const;
123 
124  //- Return first entry
125  inline link* first();
126 
127  //- Return const access to first entry
128  inline const link* first() const;
129 
130  //- Return last entry
131  inline link* last();
132 
133  //- Return const access to last entry
134  inline const link* last() const;
135 
136 
137  // Edit
138 
139  //- Add at head of list
140  void insert(link*);
141 
142  //- Add at tail of list
143  void append(link*);
144 
145  //- Remove and return head
146  link* removeHead();
147 
148  // Remove and return element
149  link* remove(link*);
150 
151  // Remove and return element specified by iterator
152  inline link* remove(iterator&);
153 
154  //- Clear the list
155  inline void clear();
156 
157  //- Transfer the contents of the argument into this List
158  // and annul the argument list.
159  inline void transfer(SLListBase&);
160 
161  // STL iterator
162 
163  //- An STL-conforming iterator
164  class iterator
165  {
166  friend class SLListBase;
167  friend class const_iterator;
168 
169  // Private data
170 
171  //- Reference to the list this is an iterator for
172  SLListBase& curList_;
173 
174  //- Current element
175  link* curElmt_;
176 
177  //- Copy of the link
178  link curLink_;
179 
180  // Private Member Functions
181 
182  //- Construct for a given SLListBase with NULL element and link.
183  // Only used to create endIter
184  inline iterator(SLListBase&);
185 
186  public:
187 
188  //- Construct for a given SLListBase and link
189  inline iterator(SLListBase&, link*);
190 
191  // Member operators
192 
193  inline void operator=(const iterator&);
194 
195  inline bool operator==(const iterator&) const;
196  inline bool operator!=(const iterator&) const;
197 
198  inline link& operator*();
199 
200  inline iterator& operator++();
201  inline iterator operator++(int);
202  };
203 
204  inline iterator begin();
205  inline const iterator& end();
206 
207 
208  // STL const_iterator
209 
210  //- An STL-conforming const_iterator
211  class const_iterator
212  {
213  // Private data
214 
215  //- Reference to the list this is an iterator for
216  const SLListBase& curList_;
217 
218  //- Current element
219  const link* curElmt_;
220 
221  public:
222 
223  //- Construct for a given SLListBase and link
224  inline const_iterator(const SLListBase&, const link*);
225 
226  //- Construct from a non-const iterator
227  inline const_iterator(const iterator&);
228 
229 
230  // Member operators
231 
232  inline void operator=(const const_iterator&);
233 
234  inline bool operator==(const const_iterator&) const;
235  inline bool operator!=(const const_iterator&) const;
236 
237  inline const link& operator*();
238 
239  inline const_iterator& operator++();
240  inline const_iterator operator++(int);
241  };
242 
243  inline const_iterator cbegin() const;
244  inline const const_iterator& cend() const;
245 
246  inline const_iterator begin() const;
247  inline const const_iterator& end() const;
248 
249 
250 private:
251 
252  //- Iterator returned by end()
253  static iterator endIter_;
254 
255  //- const_iterator returned by end()
256  static const_iterator endConstIter_;
257 };
258 
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 } // End namespace Foam
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 #include "SLListBaseI.H"
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #endif
271 
272 // ************************************************************************* //
link * first()
Return first entry.
Definition: SLListBaseI.H:80
bool empty() const
Return true if the list is empty.
Definition: SLListBaseI.H:73
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
friend class iterator
Definition: SLListBase.H:93
Base singly-linked list.
Definition: SLListBase.H:50
void clear()
Clear the list.
Definition: SLListBaseI.H:131
void transfer(SLListBase &)
Transfer the contents of the argument into this List.
Definition: SLListBaseI.H:138
An STL-conforming const_iterator.
Definition: SLListBase.H:210
tmp< fvMatrix< Type > > operator*(const DimensionedField< scalar, volMesh > &, const fvMatrix< Type > &)
void append(link *)
Add at tail of list.
Definition: SLListBase.C:62
SLListBase()
Null construct.
Definition: SLListBaseI.H:45
label size() const
Return number of elements in list.
Definition: SLListBaseI.H:67
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Base singly-linked list.
void insert(link *)
Add at head of list.
Definition: SLListBase.C:45
const const_iterator & cend() const
Definition: SLListBaseI.H:339
const iterator & end()
Definition: SLListBaseI.H:239
iterator begin()
Definition: SLListBaseI.H:225
const_iterator cbegin() const
Definition: SLListBaseI.H:325
link * removeHead()
Remove and return head.
Definition: SLListBase.C:78
volScalarField & p
bool operator!=(const particle &, const particle &)
Definition: particle.C:145
~SLListBase()
Destructor.
Definition: SLListBaseI.H:61
An STL-conforming iterator.
Definition: SLListBase.H:163
friend class const_iterator
Definition: SLListBase.H:96
System bool.
Namespace for OpenFOAM.
link * last()
Return last entry.
Definition: SLListBaseI.H:106