Loading...
Searching...
No Matches
labelRangesI.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31inline Foam::labelRanges::labelRanges(const label initialCapacity)
32:
33 ranges_(initialCapacity)
34{}
35
38:
39 ranges_(list)
40{}
41
42
44:
45 ranges_(std::move(list))
46{}
47
48
49template<int AnySizeMin>
51(
53)
55 ranges_(std::move(list))
56{}
57
58
59// * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
60
63(
64 const UList<labelRange>* list,
65 const label idx,
66 const label subIdx
69 list_(list),
70 index_(idx),
71 subIndex_(subIdx)
72{}
73
74
76operator*() const
77{
78 return (*list_)[index_][subIndex_];
79}
80
81
85{
86 // TBD: trap (index_ >= list_->size()) and make a no-op?
87 if (++subIndex_ >= (*list_)[index_].size())
88 {
89 // Move to the next range
90 ++index_;
91 subIndex_ = 0;
92 }
93
94 return *this;
95}
96
97
100operator++(int)
101{
102 const_iterator old(*this);
103 this->operator++();
104 return old;
105}
106
107
108inline constexpr bool
109Foam::labelRanges::const_iterator::
110operator==
111(
112 const const_iterator& iter
113) const noexcept
114{
115 return
116 (
117 index_ == iter.index_
118 && subIndex_ == iter.subIndex_
119 );
120}
121
122
123inline constexpr bool
124Foam::labelRanges::const_iterator::
125operator!=
126(
127 const const_iterator& iter
128) const noexcept
130 return !(*this == iter);
131}
132
133
134// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135
136inline Foam::label Foam::labelRanges::totalSize() const noexcept
137{
138 label total = 0;
139 for (const labelRange& range : ranges_)
140 {
141 if (range.size() > 0) // Ignore negative size (paranoid)
142 {
143 total += range.size();
144 }
145 }
146 return total;
147}
148
149
150inline bool Foam::labelRanges::contains(const label value) const noexcept
151{
152 for (const labelRange& range : ranges_)
153 {
154 if (range.contains(value))
155 {
156 return true;
157 }
159
160 return false;
161}
162
163
164template<class... Args>
166{
167 return ranges_.emplace_back(args...);
168}
169
170
171inline void Foam::labelRanges::sort()
172{
173 Foam::sort(ranges_);
174}
175
176
177// * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
178
181{
182 return const_iterator(&ranges_);
183}
184
185
188{
189 return const_iterator(&ranges_, ranges_.size());
190}
191
192
195{
196 return const_iterator(&ranges_);
197}
198
199
202{
203 return const_iterator(&ranges_, ranges_.size());
204}
205
206
208Foam::labelRanges::cbegin(const label i) const
209{
210 if (i <= 0) return this->cbegin();
211
212 label idx = 0;
213 label subIdx = i;
214
215 for (const labelRange& range : ranges_)
216 {
217 if (subIdx < range.size())
218 {
219 return const_iterator(&ranges_, idx, subIdx);
220 }
221 else
222 {
223 ++idx;
224 if (range.size() > 0) // Ignore negative size (paranoid)
225 {
226 subIdx -= range.size();
227 }
228 }
230
231 return this->cend();
232}
233
234
236Foam::labelRanges::begin(const label i) const
237{
238 return this->cbegin(i);
239}
240
241
242// ************************************************************************* //
scalar range
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
Forward input iterator with const access.
label operator*() const
Return the current label.
constexpr const_iterator(const UList< labelRange > *list, const label idx=0, const label subIdx=0) noexcept
Construct from range list at given index (and sub-index).
labelRange & emplace_back(Args &&... args)
Construct a range element at the end of the list, return reference to the new element.
labelRanges()=default
Default construct.
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the list.
const_iterator begin() const noexcept
A const_iterator set to the beginning of the list.
label totalSize() const noexcept
The linear size (sum of all the element sizes).
bool contains(const label value) const noexcept
True if the value is contained within any of the sub-ranges.
void sort()
Inplace sort of the range elements.
const const_iterator cend() const noexcept
A const_iterator set to beyond the end of the list.
const const_iterator end() const noexcept
A const_iterator set to beyond the end of the list.
void sort(UList< T > &list)
Sort the list.
Definition UList.C:283
const direction noexcept
Definition scalarImpl.H:265
Foam::argList args(argc, argv)