UIndirectList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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::UIndirectList
26 
27 Description
28  A List with indirect addressing.
29 
30  Like IndirectList but does not store addressing.
31 
32  Note the const_cast of the completeList. This is so we can use it both
33  on const and non-const lists. Alternative would be to have a const_
34  variant etc.
35 
36 SourceFiles
37  UIndirectListI.H
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef UIndirectList_H
42 #define UIndirectList_H
43 
44 #include "List.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of friend functions and operators
52 template<class T> class UIndirectList;
53 template<class T> void writeEntry(Ostream& os, const UIndirectList<T>&);
54 template<class T> Ostream& operator<<(Ostream&, const UIndirectList<T>&);
55 
56 /*---------------------------------------------------------------------------*\
57  Class UIndirectList Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 template<class T>
61 class UIndirectList
62 {
63  // Private Data
64 
65  //- Reference to the complete list
66  UList<T>& completeList_;
67 
68  //- Indices into the complete list
69  const UList<label>& addressing_;
70 
71 
72 public:
73 
74  // Constructors
75 
76  //- Construct given the complete list and the addressing array
77  inline UIndirectList(const UList<T>&, const UList<label>&);
78 
79  //- Copy constructor
80  UIndirectList(const UIndirectList<T>&) = default;
81 
82 
83  // Member Functions
84 
85  // Access
86 
87  //- Return the number of elements in the list
88  inline label size() const;
89 
90  //- Return true if the list is empty (ie, size() is zero).
91  inline bool empty() const;
92 
93  //- Return the first element of the list.
94  inline T& first();
95 
96  //- Return first element of the list.
97  inline const T& first() const;
98 
99  //- Return the last element of the list.
100  inline T& last();
101 
102  //- Return the last element of the list.
103  inline const T& last() const;
104 
105  //- Return the forward circular index, i.e. the next index
106  // which returns to the first at the end of the list
107  inline label fcIndex(const label i) const;
108 
109  //- Return the reverse circular index, i.e. the previous index
110  // which returns to the last at the beginning of the list
111  inline label rcIndex(const label i) const;
112 
113  //- Return the complete list
114  inline const UList<T>& completeList() const;
115 
116  //- Return the list addressing
117  inline const List<label>& addressing() const;
118 
119 
120  // Member Operators
121 
122  //- Return the addressed elements as a List
123  inline List<T> operator()() const;
124 
125  //- Return non-const access to an element
126  inline T& operator[](const label);
127 
128  //- Return const access to an element
129  inline const T& operator[](const label) const;
130 
131  //- Assignment to UList of addressed elements
132  inline void operator=(const UList<T>&);
133 
134  //- Assignment to UIndirectList of addressed elements
135  inline void operator=(const UIndirectList<T>&);
136 
137  //- Assignment of all entries to the given value
138  inline void operator=(const T&);
139 
140  //- Equality comparison. Compares element-by-element.
141  inline bool operator==(const UIndirectList<T>&) const;
142 
143  //- Inequality comparison. Compares element-by-element.
144  inline bool operator!=(const UIndirectList<T>&) const;
145 
146 
147  // STL type definitions
148 
149  //- Type of values the UList contains.
150  typedef T value_type;
151 
152  //- Type that can be used for storing into
153  // UList::value_type objects.
154  typedef T& reference;
155 
156  //- Type that can be used for storing into
157  // constant UList::value_type objects
158  typedef const T& const_reference;
159 
160  //- The type that can represent the difference between any two
161  // UList iterator objects.
162  typedef label difference_type;
163 
164  //- The type that can represent the size of a UList.
165  typedef label size_type;
166 
167 
168  // STL iterator
169  // Random access iterator for traversing UIndirectList
170 
171  //- An STL-conforming iterator
172  class iterator
173  {
174  UList<T>& l_;
175 
177 
178  public:
179 
180  friend class const_iterator;
181 
182  //- Construct for a given UList and addressing iterator
183  inline iterator
184  (
185  UList<T>&,
187  );
188 
189  // STL iterator type definitions
190 
192  typedef T value_type;
193  typedef T* pointer;
194  typedef T& reference;
195  typedef std::random_access_iterator_tag iterator_category;
196 
197  // Member Operators
198 
199  inline bool operator==(const iterator&) const;
200  inline bool operator!=(const iterator&) const;
201 
202  inline T& operator*() const;
203  inline T& operator()() const;
204 
205  inline iterator operator++();
206  inline iterator operator++(const int);
207 
208  inline iterator operator--();
209  inline iterator operator--(const int);
210 
211  inline iterator operator+=(const label);
212  inline iterator operator-=(const label);
213 
214  inline iterator operator+(const label) const;
215  inline iterator operator-(const label) const;
216 
217  inline label operator-(const iterator&) const;
218 
219  inline T& operator[](const label);
220 
221  inline bool operator<(const iterator&) const;
222  inline bool operator>(const iterator&) const;
223 
224  inline bool operator<=(const iterator&) const;
225  inline bool operator>=(const iterator&) const;
226  };
227 
228  //- Return an iterator to begin traversing the UIndirectList
229  inline iterator begin();
230 
231  //- Return an iterator to end traversing the UIndirectList
232  inline iterator end();
233 
234 
235  // STL const_iterator
236  // Random access iterator for traversing UIndirectList
237 
238  //- An STL-conforming const_iterator
239  class const_iterator
240  {
241  const UList<T>& l_;
242 
244 
245  public:
246 
247  //- Construct for a given UList and addressing iterator
248  inline const_iterator
249  (
250  const UList<T>&,
252  );
253 
254  // STL iterator type definitions
255 
257  typedef T value_type;
258  typedef const T* pointer;
259  typedef const T& reference;
260  typedef std::random_access_iterator_tag iterator_category;
261 
262  // Member Operators
263 
264  inline bool operator==(const const_iterator&) const;
265  inline bool operator!=(const const_iterator&) const;
266 
267  inline const T& operator*() const;
268  inline const T& operator()() const;
269 
270  inline const_iterator operator++();
271  inline const_iterator operator++(const int);
272 
273  inline const_iterator operator--();
274  inline const_iterator operator--(const int);
275 
276  inline const_iterator operator+=(const label);
277  inline const_iterator operator-=(const label);
278 
279  inline const_iterator operator+(const label) const;
280  inline const_iterator operator-(const label) const;
281 
282  inline label operator-(const const_iterator&) const;
283 
284  inline const T& operator[](const label);
285 
286  inline bool operator<(const const_iterator&) const;
287  inline bool operator>(const const_iterator&) const;
288 
289  inline bool operator<=(const const_iterator&) const;
290  inline bool operator>=(const const_iterator&) const;
291  };
292 
293  //- Return an const_iterator to begin traversing the UIndirectList
294  inline const_iterator cbegin() const;
295 
296  //- Return an const_iterator to end traversing the UIndirectList
297  inline const_iterator cend() const;
298 
299  //- Return an const_iterator to begin traversing the UIndirectList
300  inline const_iterator begin() const;
301 
302  //- Return an const_iterator to end traversing the UIndirectList
303  inline const_iterator end() const;
304 
305 
306  // Ostream operator
307 
308  //- Write UIndirectList to Ostream
309  // Binary output is currently still a bit of a problem
310  friend Ostream& operator<< <T>
311  (
312  Ostream&,
313  const UIndirectList<T>&
314  );
315 };
316 
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #include "UIndirectListI.H"
325 
326 #ifdef NoRepository
327  #include "UIndirectListIO.C"
328 #endif
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #endif
333 
334 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An STL-conforming const_iterator.
bool operator!=(const const_iterator &) const
const_iterator(const UList< T > &, const UList< label >::const_iterator &)
Construct for a given UList and addressing iterator.
const_iterator operator-=(const label)
bool operator>(const const_iterator &) const
bool operator<=(const const_iterator &) const
const T & operator[](const label)
bool operator>=(const const_iterator &) const
std::random_access_iterator_tag iterator_category
bool operator==(const const_iterator &) const
bool operator<(const const_iterator &) const
const_iterator operator-(const label) const
const_iterator operator+=(const label)
const_iterator operator+(const label) const
An STL-conforming iterator.
iterator operator-(const label) const
bool operator!=(const iterator &) const
iterator operator+(const label) const
bool operator>(const iterator &) const
iterator(UList< T > &, const UList< label >::const_iterator &)
Construct for a given UList and addressing iterator.
std::random_access_iterator_tag iterator_category
iterator operator+=(const label)
bool operator==(const iterator &) const
bool operator<(const iterator &) const
iterator operator-=(const label)
bool operator<=(const iterator &) const
bool operator>=(const iterator &) const
A List with indirect addressing.
Definition: UIndirectList.H:61
label size_type
The type that can represent the size of a UList.
UIndirectList(const UList< T > &, const UList< label > &)
Construct given the complete list and the addressing array.
label difference_type
The type that can represent the difference between any two.
T & first()
Return the first element of the list.
T value_type
Type of values the UList contains.
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
const_iterator cbegin() const
Return an const_iterator to begin traversing the UIndirectList.
label size() const
Return the number of elements in the list.
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
const_iterator cend() const
Return an const_iterator to end traversing the UIndirectList.
bool empty() const
Return true if the list is empty (ie, size() is zero).
const UList< T > & completeList() const
Return the complete list.
bool operator==(const UIndirectList< T > &) const
Equality comparison. Compares element-by-element.
T & operator[](const label)
Return non-const access to an element.
T & reference
Type that can be used for storing into.
iterator begin()
Return an iterator to begin traversing the UIndirectList.
bool operator!=(const UIndirectList< T > &) const
Inequality comparison. Compares element-by-element.
void operator=(const UList< T > &)
Assignment to UList of addressed elements.
List< T > operator()() const
Return the addressed elements as a List.
iterator end()
Return an iterator to end traversing the UIndirectList.
T & last()
Return the last element of the list.
const T & const_reference
Type that can be used for storing into.
const List< label > & addressing() const
Return the list addressing.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
Namespace for OpenFOAM.
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
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)