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