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