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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::SLListBase
29 
30 Description
31  Base for singly-linked lists.
32 
33  The iterators associated with the list only have a core functionality
34  for navigation, with additional functionality to be added by inheriting
35  classes. The node iterators always have a node-pointer as the
36  first member data, which allows reinterpret_cast from anything else with
37  a nullptr as its first data member.
38  The nullObject is such an item (with a nullptr data member).
39 
40 SourceFiles
41  SLListBaseI.H
42  SLListBase.C
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef SLListBase_H
47 #define SLListBase_H
48 
49 #include "label.H"
50 #include "uLabel.H"
51 #include "stdFoam.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 /*---------------------------------------------------------------------------*\
59  Class SLListBase Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class SLListBase
63 {
64 public:
65 
66  //- The structure for a singly-linked storage node
67  struct link
68  {
69  //- Pointer to next entry in list
70  link* next_ = nullptr;
71 
72  //- Default construct
73  link() = default;
74  };
75 
76 
77 private:
78 
79  // Private Data
80 
81  //- A pointer to the last element.
82  // last_->next_ points to first element, i.e. circular storage
83  link* last_ = nullptr;
84 
85  //- Number of elements in the list
86  label size_ = 0;
87 
88 
89 protected:
90 
91  // Protected Member Functions
92 
93  //- Factory method to return an iterator end
94  // Simply reinterprets a NullObject as a SLListBase iterator.
95  template<class IteratorType>
96  inline static const IteratorType& iterator_end();
97 
98  //- Factory method to return an iterator rend
99  // Deleted for SLListBase
100  template<class IteratorType>
101  static const IteratorType& iterator_rend() = delete;
102 
103  //- Return iterator to first item or end-iterator if list is empty
104  // Removes constness which the caller promises to manage.
105  template<class IteratorType>
106  inline IteratorType iterator_first() const;
107 
108  //- Return iterator to last item or end-iterator if list is empty
109  // Removes constness which the caller promises to manage.
110  template<class IteratorType>
111  inline IteratorType iterator_last() const;
112 
113 public:
114 
115  // Forward declaration of iterators
116 
117  class iterator;
118  friend class iterator;
119 
120  class const_iterator;
121  friend class const_iterator;
122 
123 
124  // Generated Methods
125 
126  //- Default construct
127  SLListBase() = default;
128 
129  //- No copy construct
130  SLListBase(const SLListBase&) = delete;
131 
132  //- No copy assignment
133  void operator=(const SLListBase&) = delete;
134 
135  //- Destructor
136  ~SLListBase() = default;
137 
138 
139  // Member Functions
140 
141  //- The number of elements in list
142  inline label size() const noexcept;
143 
144  //- True if the list is empty
145  inline bool empty() const noexcept;
146 
147  //- Return first entry
148  inline link* first();
149 
150  //- Return const access to first entry
151  inline const link* first() const;
152 
153  //- Return last entry
154  inline link* last();
155 
156  //- Return const access to last entry
157  inline const link* last() const;
158 
159 
160  //- Add at head of list
161  void insert(link* item);
162 
163  //- Add at tail of list
164  void append(link* item);
165 
166  //- Remove and return head
167  link* removeHead();
168 
169  // Remove and return element
170  link* remove(link* item);
171 
172  // Remove and return element specified by iterator
173  inline link* remove(iterator& iter);
174 
175  //- Clear the list
176  inline void clear();
177 
178  //- Swap the contents of list
179  inline void swap(SLListBase& lst);
180 
181  //- Transfer the contents of the argument into this list
182  //- and annul the argument list.
183  inline void transfer(SLListBase& lst);
184 
185 
186  // iterator
187 
188  //- A primitive non-const node iterator.
189  // Must normally be extended by inheriting classes.
190  class iterator
191  {
192  friend class SLListBase;
193  friend class const_iterator;
194 
195  //- The selected node.
196  // MUST be the first member for easy comparison between iterators
197  // and for reinterpret_cast from nullObject
198  link* node_;
199 
200  //- The list being iterated on (as pointer for bitwise copy)
201  SLListBase* list_;
202 
203  //- Copy of the node next pointer (to use after removal)
204  link copy_;
205 
206  public:
207 
208  //- Copy construct
209  iterator(const iterator&) = default;
210 
211  //- Construct for a node on the list
212  inline iterator(SLListBase* list, link* item);
213 
214  //- The storage node
215  inline link* get_node() const;
216 
217  //- Pointing at a valid storage node
218  inline bool good() const;
219 
220  //- Deprecated(2019-01) Pointing at a valid storage node
221  // \deprecated(2019-01) - use good() method
222  FOAM_DEPRECATED_FOR(2019-01, "good() method")
223  bool found() const
224  {
225  return this->good();
226  }
227 
228  //- Cannot move backward through list
229  inline void prev() = delete;
230 
231  //- Move forward through list
232  inline void next();
233 
234  //- Copy assignment
235  inline void operator=(const iterator& iter);
236 
237  inline bool operator==(const iterator& iter) const;
238  inline bool operator!=(const iterator& iter) const;
239  };
240 
241 
242  // STL const_iterator
243 
244  //- A primitive const node iterator.
245  // Must normally be extended by inheriting classes.
246  class const_iterator
247  {
248  //- The selected node.
249  // MUST be the first member for easy comparison between iterators
250  // and for reinterpret_cast from nullObject
251  const link* node_;
252 
253  //- The list being iterated on (as pointer for bitwise copy)
254  const SLListBase* list_;
255 
256  public:
257 
258  //- Copy construct
259  const_iterator(const const_iterator&) = default;
260 
261  //- Construct for a node on the list
262  inline const_iterator(const SLListBase* list, const link* item);
263 
264  //- Construct from a non-const iterator
265  inline const_iterator(const SLListBase::iterator& iter);
266 
267  //- The storage node
268  inline const link* get_node() const;
269 
270  //- Pointing at a valid storage node
271  inline bool good() const;
272 
273  //- Deprecated(2019-01) Pointing at a valid storage node
274  // \deprecated(2019-01) - use good() method
275  FOAM_DEPRECATED_FOR(2019-01, "good() method")
276  bool found() const
277  {
278  return this->good();
279  }
280 
281  //- Cannot move backward through list
282  inline void prev() = delete;
283 
284  //- Move forward through list
285  inline void next();
286 
287  //- Copy assignment
288  const_iterator& operator=(const const_iterator&) = default;
289 
290  inline bool operator==(const const_iterator& iter) const;
291  inline bool operator!=(const const_iterator& iter) const;
292  };
293 
294 
295  //- Iterator to first item in list with non-const access
296  inline iterator begin();
297 
298  //- Iterator to first item in list with const access
299  inline const_iterator cbegin() const;
300 
301  //- No reverse iteration
302  const_iterator crbegin() const = delete;
303 
304  //- End of list for iterators
305  inline const iterator& end();
306 
307  //- End of list for iterators
308  inline const const_iterator& cend() const;
309 
310  //- No reverse iteration
311  const const_iterator& crend() const = delete;
312 };
313 
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 } // End namespace Foam
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 #include "SLListBaseI.H"
322 
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
324 
325 #endif
326 
327 // ************************************************************************* //
Foam::SLListBase::cbegin
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition: SLListBaseI.H:345
Foam::SLListBase::last
link * last()
Return last entry.
Definition: SLListBaseI.H:112
Foam::SLListBase::first
link * first()
Return first entry.
Definition: SLListBaseI.H:86
Foam::SLListBase::const_iterator::operator==
bool operator==(const const_iterator &iter) const
Definition: SLListBaseI.H:327
Foam::SLListBase::const_iterator::operator!=
bool operator!=(const const_iterator &iter) const
Definition: SLListBaseI.H:336
Foam::SLListBase::const_iterator::const_iterator
const_iterator(const const_iterator &)=default
Copy construct.
Foam::SLListBase::remove
link * remove(link *item)
Definition: SLListBase.C:103
Foam::SLListBase::append
void append(link *item)
Add at tail of list.
Definition: SLListBase.C:56
Foam::SLListBase::clear
void clear()
Clear the list.
Definition: SLListBaseI.H:137
Foam::SLListBase::iterator_rend
static const IteratorType & iterator_rend()=delete
Factory method to return an iterator rend.
Foam::SLListBase::begin
iterator begin()
Iterator to first item in list with non-const access.
Definition: SLListBaseI.H:249
Foam::SLListBase::iterator_last
IteratorType iterator_last() const
Return iterator to last item or end-iterator if list is empty.
Definition: SLListBaseI.H:57
Foam::SLListBase::const_iterator::prev
void prev()=delete
Cannot move backward through list.
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Foam::SLListBase::const_iterator::good
bool good() const
Pointing at a valid storage node.
Definition: SLListBaseI.H:304
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
SLListBaseI.H
Foam::SLListBase::const_iterator::get_node
const link * get_node() const
The storage node.
Definition: SLListBaseI.H:298
Foam::SLListBase::removeHead
link * removeHead()
Remove and return head.
Definition: SLListBase.C:77
Foam::SLListBase::iterator_end
static const IteratorType & iterator_end()
Factory method to return an iterator end.
Definition: SLListBaseI.H:35
Foam::SLListBase::const_iterator::found
bool found() const
Deprecated(2019-01) Pointing at a valid storage node.
Definition: SLListBase.H:275
Foam::SLListBase::iterator
friend class iterator
Definition: SLListBase.H:116
Foam::SLListBase::operator=
void operator=(const SLListBase &)=delete
No copy assignment.
Foam::SLListBase::swap
void swap(SLListBase &lst)
Swap the contents of list.
Definition: SLListBaseI.H:144
Foam::SLListBase::transfer
void transfer(SLListBase &lst)
Definition: SLListBaseI.H:156
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SLListBase::iterator
A primitive non-const node iterator.
Definition: SLListBase.H:189
Foam::SLListBase::crbegin
const_iterator crbegin() const =delete
No reverse iteration.
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::SLListBase::const_iterator
A primitive const node iterator.
Definition: SLListBase.H:245
Foam::SLListBase::const_iterator::operator=
const_iterator & operator=(const const_iterator &)=default
Copy assignment.
Foam::SLListBase::end
const iterator & end()
End of list for iterators.
Definition: SLListBaseI.H:261
Foam::SLListBase::crend
const const_iterator & crend() const =delete
No reverse iteration.
Foam::SLListBase::size
label size() const noexcept
The number of elements in list.
Definition: SLListBaseI.H:73
Foam::SLListBase::SLListBase
SLListBase()=default
Default construct.
label.H
Foam::SLListBase
Base for singly-linked lists.
Definition: SLListBase.H:61
stdFoam.H
bool
bool
Definition: EEqn.H:20
Foam::SLListBase::~SLListBase
~SLListBase()=default
Destructor.
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::SLListBase::const_iterator
friend class const_iterator
Definition: SLListBase.H:119
Foam::SLListBase::const_iterator::next
void next()
Move forward through list.
Definition: SLListBaseI.H:310
uLabel.H
Foam::SLListBase::empty
bool empty() const noexcept
True if the list is empty.
Definition: SLListBaseI.H:79
Foam::SLListBase::iterator_first
IteratorType iterator_first() const
Return iterator to first item or end-iterator if list is empty.
Definition: SLListBaseI.H:42
Foam::SLListBase::cend
const const_iterator & cend() const
End of list for iterators.
Definition: SLListBaseI.H:268
Foam::SLListBase::insert
void insert(link *item)
Add at head of list.
Definition: SLListBase.C:34