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-2021 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#include <algorithm>
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
32inline constexpr Foam::sliceRange::sliceRange() noexcept
33:
34 start_(0),
35 size_(0),
36 stride_(0)
37{}
38
39
41(
42 const label beg,
43 const label len,
44 const label stride
46:
47 start_(beg),
48 size_(len),
49 stride_(stride)
50{}
51
52
53// * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
54
56:
57 stride_(1),
58 value_(0)
59{}
60
61
63(
64 const label val,
65 const label stride
67:
68 stride_(stride),
69 value_(val)
70{}
71
72
73inline Foam::label
76{
77 const label old(value_);
78 next();
79 return old;
80}
81
82
83// * * * * * * * * * * * * * * Forward Iterators * * * * * * * * * * * * * * //
84
85inline constexpr Foam::label
87operator[](const label n) const noexcept
88{
89 return value(n);
90}
91
92
96{
97 next();
98 return *this;
99}
100
101
104operator++(int) noexcept
105{
106 const_iterator old(*this);
107 next();
108 return old;
109}
110
111
115{
116 prev();
117 return *this;
118}
119
120
123operator--(int) noexcept
124{
125 const_iterator old(*this);
126 prev();
127 return old;
128}
129
130
133operator+=(const label n) noexcept
134{
135 next(n);
136 return *this;
137}
138
139
142operator-=(const label n) noexcept
143{
144 prev(n);
145 return *this;
146}
147
148
151operator+(const label n) const noexcept
152{
153 return const_iterator(value(n), stride());
154}
155
156
159operator-(const label n) const noexcept
160{
161 return const_iterator(value(-n), stride());
162}
163
164
165inline constexpr Foam::label
167operator-(const const_iterator& iter) const noexcept
168{
169 return (stride() ? (value() - iter.value()) / stride() : label{0});
170}
171
172
173inline constexpr bool
175operator==(const const_iterator& iter) const noexcept
176{
177 return (value() == iter.value());
178}
179
180
181inline constexpr bool
183operator<(const const_iterator& iter) const noexcept
184{
185 return (value() < iter.value());
186}
187
188
189// * * * * * * * * * * * * * * Reverse Iterators * * * * * * * * * * * * * * //
190
191inline constexpr Foam::label
193operator[](const label n) const noexcept
194{
195 return value(-n);
196}
197
198
202{
203 prev();
204 return *this;
205}
206
207
210operator++(int) noexcept
211{
212 const_reverse_iterator old(*this);
213 prev();
214 return old;
215}
216
217
221{
222 next();
223 return *this;
224}
225
226
229operator--(int) noexcept
230{
232 next();
233 return old;
234}
235
236
239operator+=(const label n) noexcept
240{
241 prev(n);
242 return *this;
243}
244
245
248operator-=(const label n) noexcept
249{
250 next(n);
251 return *this;
252}
253
254
257operator+(const label n) const noexcept
258{
259 return const_reverse_iterator(value(-n), stride());
260}
261
262
265operator-(const label n) const noexcept
266{
267 return const_reverse_iterator(value(n), stride());
268}
269
270
271inline constexpr Foam::label
273operator-(const const_reverse_iterator& iter) const noexcept
274{
275 return (stride() ? (iter.value() - value()) / stride() : label{0});
276}
277
278
279inline constexpr bool
281operator==(const const_reverse_iterator& iter) const noexcept
282{
283 return (value() == iter.value());
284}
285
286
287inline constexpr bool
289operator<(const const_reverse_iterator& iter) const noexcept
290{
291 return (iter.value() < value());
292}
293
294
295// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
296
299{
300 return indexer(start_, stride_);
301}
302
303
305Foam::sliceRange::at(const label i) const
306{
307 return
309 (
310 start_ + ((i < 0 || i > size_) ? size_ : i) * stride_,
311 stride_
312 );
313}
314
315
318{
319 return const_iterator(start_, stride_);
320}
321
322
325{
326 return const_iterator(start_, stride_);
327}
328
329
332{
333 return const_iterator(start_ + size_*stride_, stride_);
334}
335
336
339{
340 return const_iterator(start_ + size_*stride_, stride_);
341}
342
343
346{
347 return const_reverse_iterator(start_ + (size_-1)*stride_, stride_);
348}
349
350
353{
354 return const_reverse_iterator(start_ + (size_-1)*stride_, stride_);
355}
356
357
360{
361 return const_reverse_iterator(start_ - stride_, stride_);
362}
363
364
367{
368 return const_reverse_iterator(start_ - stride_, stride_);
369}
370
371
372// ************************************************************************* //
label n
friend complex operator+(const complex &c1, const complex &c2)
Definition: complexI.H:291
friend bool operator==(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:97
Bidirectional input iterator with const access.
Definition: sliceRange.H:281
constexpr label operator[](const label n) const noexcept
Offset dereference operator.
Definition: sliceRangeI.H:87
constexpr bool operator<(const const_iterator &iter) const noexcept
Compare less-than values (ignore stride)
Definition: sliceRangeI.H:183
const_iterator & operator+=(const label n) noexcept
Arbitrary increment.
Definition: sliceRangeI.H:133
const_iterator & operator-=(const label n) noexcept
Arbitrary decrement.
Definition: sliceRangeI.H:142
const_iterator & operator--() noexcept
Prefix decrement.
Definition: sliceRangeI.H:114
const_iterator & operator++() noexcept
Prefix increment.
Definition: sliceRangeI.H:95
Bidirectional reverse input iterator with const access.
Definition: sliceRange.H:379
const_reverse_iterator & operator++() noexcept
Prefix increment.
Definition: sliceRangeI.H:201
constexpr label operator[](const label n) const noexcept
Offset dereference operator.
Definition: sliceRangeI.H:193
const_reverse_iterator & operator+=(const label n) noexcept
Arbitrary increment.
Definition: sliceRangeI.H:239
const_reverse_iterator & operator--() noexcept
Prefix decrement.
Definition: sliceRangeI.H:220
const_reverse_iterator & operator-=(const label n) noexcept
Arbitrary decrement.
Definition: sliceRangeI.H:248
constexpr bool operator<(const const_reverse_iterator &iter) const noexcept
Reverse compare less-than values (ignore stride)
Definition: sliceRangeI.H:289
A value indexer, for iteration or generation.
Definition: sliceRange.H:209
label operator()() noexcept
Apply a postfix increment and return the current value.
Definition: sliceRangeI.H:75
constexpr indexer() noexcept
Default construct with zero value and stride = 1.
Definition: sliceRangeI.H:55
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the range.
Definition: sliceRangeI.H:324
constexpr sliceRange() noexcept
Default construct an empty slice (0,0,0)
Definition: sliceRangeI.H:32
const_reverse_iterator crbegin() const noexcept
A const_reverse_iterator set to 1 before the end of range.
Definition: sliceRangeI.H:352
const_iterator end() const noexcept
A const_iterator set to 1 beyond the end of the range.
Definition: sliceRangeI.H:331
const_reverse_iterator rbegin() const noexcept
A const_reverse_iterator set to 1 before the end of range.
Definition: sliceRangeI.H:345
const_iterator begin() const noexcept
A const_iterator set to the beginning of the range.
Definition: sliceRangeI.H:317
const_iterator cend() const noexcept
A const_iterator set to 1 beyond the end of the range.
Definition: sliceRangeI.H:338
const_iterator at(const label i) const
Definition: sliceRangeI.H:305
const_reverse_iterator rend() const noexcept
A const_reverse_iterator set to 1 before the begin of range.
Definition: sliceRangeI.H:359
indexer generator() const
Return a forward values generator.
Definition: sliceRangeI.H:298
const_reverse_iterator crend() const noexcept
A const_reverse_iterator set to 1 before the begin of range.
Definition: sliceRangeI.H:366
zeroField operator-() const noexcept
Definition: zeroField.H:85
const direction noexcept
Definition: Scalar.H:223