Loading...
Searching...
No Matches
OffsetRangeI.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) 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
30template<class IntType>
32:
33 start_(0),
34 size_(0),
35 total_(0)
36{}
37
38
39template<class IntType>
40inline constexpr Foam::OffsetRange<IntType>::OffsetRange(IntType len) noexcept
41:
42 start_(0),
43 size_(len),
44 total_(len)
45{}
46
47
48template<class IntType>
50(
51 IntType beg,
52 IntType len,
53 IntType tot
55:
56 start_(beg),
57 size_(len),
58 total_(tot)
59{}
60
61
62// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63
64template<class IntType>
65inline IntType Foam::OffsetRange<IntType>::at_value(IntType i) const noexcept
66{
67 return (start_ + ((i < 0 || i > size_) ? size_ : i));
68}
69
70
71template<class IntType>
73{
74 return (start_);
75}
76
77
78template<class IntType>
80{
81 return (start_ + size_);
82}
83
84
85template<class IntType>
87{
88 return (start_ + (size_ - 1));
89}
90
91
92template<class IntType>
94{
95 return (start_ - 1);
96}
97
98
99template<class IntType>
101{
102 start_ = 0;
103 size_ = 0;
104 total_ = 0;
105}
106
107
108template<class IntType>
109inline void Foam::OffsetRange<IntType>::reset(IntType len) noexcept
110{
111 start_ = 0;
112 size_ = len;
113 total_ = len;
114}
115
116
117template<class IntType>
119(
120 IntType beg,
121 IntType len,
122 IntType tot
123) noexcept
124{
125 start_ = beg;
126 size_ = len;
127 total_ = tot;
128}
129
130
131template<class IntType>
132inline bool Foam::OffsetRange<IntType>::contains(IntType value) const noexcept
134 // This check is non-overflowing...
135 return (size_ && start_ <= value && (value - start_) < size_);
136}
137
138
139template<class IntType>
141(
143) const noexcept
144{
145 const auto& a = *this;
146
147 return
148 (
149 a.start() == b.start()
150 && a.size() == b.size()
151 && a.total() == b.total()
152 );
153}
154
155
156template<class IntType>
158(
160) const noexcept
161{
162 const auto& a = *this;
163
164 if (a.start() < b.start()) return -1;
165 if (b.start() < a.start()) return +1;
166
167 if (a.size() < b.size()) return -1;
168 if (b.size() < a.size()) return +1;
169
170 if (a.total() < b.total()) return -1;
171 if (b.total() < a.total()) return +1;
172
173 return 0;
175
176
177// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
178
179template<class IntType>
180inline constexpr IntType
181Foam::OffsetRange<IntType>::operator[](IntType i) const noexcept
182{
183 return (start_ + i);
184}
185
186
187// ************************************************************************* //
A tuple of integers comprising start, size, total.
Definition OffsetRange.H:82
void clear() noexcept
Reset to zero.
constexpr IntType operator[](IntType i) const noexcept
Offset dereference, without bounds checking.
IntType rend_value() const noexcept
The value 1 before the begin of start/size range.
OffsetRange(const OffsetRange &) noexcept=default
Copy construct.
int compare(const OffsetRange &b) const noexcept
Compare start/size/total in that order.
bool equals(const OffsetRange &b) const noexcept
Test equality of start/size/total.
IntType rbegin_value() const noexcept
The max value of the start/size range.
constexpr OffsetRange() noexcept
Default construct as (0,0,0).
bool contains(IntType value) const noexcept
True if the value is between the start and size range range.
IntType begin_value() const noexcept
The value at the beginning of the start/size range - same as start().
IntType end_value() const noexcept
The value 1 beyond the end of the start/size range.
void reset(IntType len) noexcept
Reset to the specified size, with start=0 and total=size.
const direction noexcept
Definition scalarImpl.H:265
volScalarField & b