Loading...
Searching...
No Matches
sliceRangeI.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) 2019-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29
32 start_(0),
33 size_(0),
34 stride_(0)
35{}
36
37
38inline constexpr Foam::sliceRange::sliceRange
39(
40 const label beg,
41 const label len,
42 const label stride
44:
45 start_(beg),
46 size_(len),
47 stride_(stride)
48{}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
54(
55 const sliceRange& b
56) const noexcept
57{
58 const auto& a = *this;
59
60 return
61 (
62 a.start() == b.start()
63 && a.size() == b.size()
64 && a.stride() == b.stride()
65 );
66}
67
68
70(
71 const sliceRange& b
72) const noexcept
73{
74 const auto& a = *this;
75
76 if (a.start() < b.start()) return -1;
77 if (b.start() < a.start()) return +1;
78
79 if (a.size() < b.size()) return -1;
80 if (b.size() < a.size()) return +1;
81
82 if (a.stride() < b.stride()) return -1;
83 if (b.stride() < a.stride()) return +1;
85 return 0;
86}
87
88
89// * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
90
92:
93 stride_(1),
94 value_(0)
95{}
96
97
99(
100 const label val,
101 const label stride
102) noexcept
104 stride_(stride),
105 value_(val)
106{}
107
108
109inline Foam::label
112{
113 const label old(value_);
114 next();
115 return old;
116}
117
118
119// * * * * * * * * * * * * * * Forward Iterators * * * * * * * * * * * * * * //
120
121inline constexpr Foam::label
123operator[](const label n) const noexcept
124{
125 return value(n);
126}
127
128
133 next();
134 return *this;
135}
136
137
140operator++(int) noexcept
141{
142 const_iterator old(*this);
143 next();
144 return old;
145}
146
147
152 prev();
153 return *this;
154}
155
156
159operator--(int) noexcept
160{
161 const_iterator old(*this);
162 prev();
163 return old;
164}
165
166
169operator+=(const label n) noexcept
171 next(n);
172 return *this;
173}
174
175
178operator-=(const label n) noexcept
180 prev(n);
181 return *this;
182}
183
184
187operator+(const label n) const noexcept
188{
189 return const_iterator(value(n), stride());
190}
191
192
195operator-(const label n) const noexcept
196{
197 return const_iterator(value(-n), stride());
198}
199
200
201inline constexpr Foam::label
203operator-(const const_iterator& iter) const noexcept
204{
205 return (stride() ? (value() - iter.value()) / stride() : label{0});
206}
207
208
209inline constexpr bool
211operator==(const const_iterator& iter) const noexcept
212{
213 return (value() == iter.value());
214}
215
216
217inline constexpr bool
219operator<(const const_iterator& iter) const noexcept
220{
221 return (value() < iter.value());
222}
223
224
225// * * * * * * * * * * * * * * Reverse Iterators * * * * * * * * * * * * * * //
226
227inline constexpr Foam::label
229operator[](const label n) const noexcept
230{
231 return value(-n);
232}
233
234
239 prev();
240 return *this;
241}
242
243
246operator++(int) noexcept
247{
249 prev();
250 return old;
251}
252
253
258 next();
259 return *this;
260}
261
262
265operator--(int) noexcept
266{
268 next();
269 return old;
270}
271
272
275operator+=(const label n) noexcept
277 prev(n);
278 return *this;
279}
280
281
284operator-=(const label n) noexcept
286 next(n);
287 return *this;
288}
289
290
293operator+(const label n) const noexcept
294{
296}
297
298
301operator-(const label n) const noexcept
302{
304}
305
306
307inline constexpr Foam::label
309operator-(const const_reverse_iterator& iter) const noexcept
310{
311 return (stride() ? (iter.value() - value()) / stride() : label{0});
312}
313
314
315inline constexpr bool
317operator==(const const_reverse_iterator& iter) const noexcept
318{
319 return (value() == iter.value());
320}
321
323inline constexpr bool
325operator<(const const_reverse_iterator& iter) const noexcept
326{
327 return (iter.value() < value());
328}
329
330
331// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
332
335{
336 return indexer(start_, stride_);
337}
338
339
341Foam::sliceRange::at(const label i) const
342{
343 return
345 (
346 start_ + ((i < 0 || i > size_) ? size_ : i) * stride_,
347 stride_
348 );
349}
350
351
354{
355 return const_iterator(start_, stride_);
356}
357
358
361{
362 return const_iterator(start_, stride_);
363}
364
365
368{
369 return const_iterator(start_ + size_*stride_, stride_);
370}
371
372
375{
376 return const_iterator(start_ + size_*stride_, stride_);
377}
378
379
382{
383 return const_reverse_iterator(start_ + (size_-1)*stride_, stride_);
384}
385
386
389{
390 return const_reverse_iterator(start_ + (size_-1)*stride_, stride_);
391}
392
393
396{
397 return const_reverse_iterator(start_ - stride_, stride_);
398}
399
400
403{
404 return const_reverse_iterator(start_ - stride_, stride_);
405}
406
407
408// ************************************************************************* //
label n
Bidirectional input iterator with const access.
Definition sliceRange.H:393
constexpr label operator[](const label n) const noexcept
Offset dereference operator.
constexpr bool operator==(const const_iterator &iter) const noexcept
Test for equality of values (ignore stride).
constexpr bool operator<(const const_iterator &iter) const noexcept
Compare less-than values (ignore stride).
const_iterator & operator+=(const label n) noexcept
Arbitrary increment.
const_iterator & operator-=(const label n) noexcept
Arbitrary decrement.
constexpr const_iterator operator+(const label n) const noexcept
Return iterator with offset.
const_iterator & operator--() noexcept
Prefix decrement.
const_iterator & operator++() noexcept
Prefix increment.
constexpr const_iterator operator-(const label n) const noexcept
Return iterator with offset.
Bidirectional reverse input iterator with const access.
Definition sliceRange.H:519
constexpr bool operator==(const const_reverse_iterator &iter) const noexcept
Test for equality of values (ignore stride).
const_reverse_iterator & operator++() noexcept
Prefix increment.
constexpr label operator[](const label n) const noexcept
Offset dereference operator.
constexpr const_reverse_iterator operator+(const label n) const noexcept
Return iterator with offset.
constexpr const_reverse_iterator operator-(const label n) const noexcept
Return iterator with offset.
const_reverse_iterator & operator+=(const label n) noexcept
Arbitrary increment.
const_reverse_iterator & operator--() noexcept
Prefix decrement.
const_reverse_iterator & operator-=(const label n) noexcept
Arbitrary decrement.
constexpr bool operator<(const const_reverse_iterator &iter) const noexcept
Reverse compare less-than values (ignore stride).
A value indexer, for iteration or generation.
Definition sliceRange.H:292
constexpr label value() const noexcept
The current value.
Definition sliceRange.H:334
constexpr label stride() const noexcept
The stride.
Definition sliceRange.H:339
void prev() noexcept
Decrement value.
Definition sliceRange.H:352
void next() noexcept
Increment value.
Definition sliceRange.H:362
label operator()() noexcept
Apply a postfix increment and return the current value.
constexpr indexer() noexcept
Default construct with zero value and stride = 1.
Definition sliceRangeI.H:84
A set of labels defined by a start, a length and a stride.
Definition sliceRange.H:65
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the range.
constexpr sliceRange() noexcept
Default construct an empty slice (0,0,0).
Definition sliceRangeI.H:23
int compare(const sliceRange &b) const noexcept
Compare start/size/stride in that order.
Definition sliceRangeI.H:63
bool equals(const sliceRange &b) const noexcept
Test equality of start/size/stride.
Definition sliceRangeI.H:47
const_reverse_iterator crbegin() const noexcept
A const_reverse_iterator set to 1 before the end of range.
const_iterator end() const noexcept
A const_iterator set to 1 beyond the end of the range.
const_reverse_iterator rbegin() const noexcept
A const_reverse_iterator set to 1 before the end of range.
const_iterator begin() const noexcept
A const_iterator set to the beginning of the range.
const_iterator cend() const noexcept
A const_iterator set to 1 beyond the end of the range.
const_iterator at(const label i) const
Return const_iterator to a position within the range, with bounds checking.
const_reverse_iterator rend() const noexcept
A const_reverse_iterator set to 1 before the begin of range.
label stride() const noexcept
The stride for the range.
Definition sliceRange.H:173
indexer generator() const
Return a forward values generator.
const_reverse_iterator crend() const noexcept
A const_reverse_iterator set to 1 before the begin of range.
const direction noexcept
Definition scalarImpl.H:265
volScalarField & b