Loading...
Searching...
No Matches
labelRanges.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 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
27Class
28 Foam::labelRanges
29
30Description
31 A list of labelRange with constrained list capabilities.
32
33SourceFiles
34 labelRangesI.H
35 labelRanges.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_labelRanges_H
40#define Foam_labelRanges_H
41
42#include "labelRange.H"
43#include "DynamicList.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
49
50// Forward Declarations
51class labelRanges;
53Ostream& operator<<(Ostream& is, const labelRanges& ranges);
55/*---------------------------------------------------------------------------*\
56 Class labelRanges Declaration
57\*---------------------------------------------------------------------------*/
58
59class labelRanges
60{
61 // Private Data
62
63 //- The list of ranges
65
66
67 // Private Member Functions
68
69 //- Insert range before specified insertion index, by copying up
70 void insertBefore(const label insert, const labelRange& range);
71
72 //- Purge empty ranges, by copying down
73 void purgeEmpty();
74
75public:
76
77 // STL type definitions
78
79 //- The value type the list contains
80 typedef labelRange value_type;
81
82 //- Input iterator with const access
84
85
86 // Generated Methods
87
88 //- Default construct
89 labelRanges() = default;
90
91 //- Default copy construct
92 labelRanges(const labelRanges&) = default;
93
94 //- Default move construct
95 labelRanges(labelRanges&&) = default;
97 //- Default copy assignment
98 labelRanges& operator=(const labelRanges&) = default;
99
100 //- Default move assignment
102
103
104 // Constructors
105
106 //- Construct an empty list with given initial capacity
107 inline explicit labelRanges(const label initialCapacity);
108
109 //- Copy construct from list of ranges
110 inline explicit labelRanges(const UList<labelRange>& list);
112 //- Move construct from list of ranges
113 inline labelRanges(List<labelRange>&& list);
114
115 //- Move construct from list of ranges
116 template<int AnySizeMin>
118
119 //- Construct from Istream.
120 explicit labelRanges(Istream& is);
121
122
123 // Member Functions
124
125 //- The list of ranges
126 const UList<labelRange>& ranges() const noexcept { return ranges_; }
127
128 //- Clear the addressable list of ranges
129 void clear() noexcept { ranges_.clear(); }
130
131 //- True if list of ranges is empty
132 bool empty() const noexcept { return ranges_.empty(); }
133
134 //- Reserve space for at least this size
135 void reserve(const label len) { ranges_.reserve(len); }
136
137 //- The linear size (sum of all the element sizes)
138 inline label totalSize() const noexcept;
139
140 //- True if the value is contained within any of the sub-ranges
141 inline bool contains(const label value) const noexcept;
142
143 //- Add the range to the list
144 bool add(const labelRange& range);
146 //- Remove the range from the list
147 bool remove(const labelRange& range);
148
149 //- Construct a range element at the end of the list,
150 //- return reference to the new element.
151 template<class... Args>
152 inline labelRange& emplace_back(Args&&... args);
154 //- Inplace sort of the range elements
155 inline void sort();
156
157 //- Return flattened list of all range labels
158 List<label> labels() const;
159
160
161 // Member Operators
162
163 //- Return the value at linear index 'i', -1 for out-of-range
164 label operator[](const label i) const;
165
166
167 // STL iterator
169 //- Forward input iterator with const access
170 class const_iterator
171 {
172 //- The list of ranges for which this is an iterator
173 const UList<labelRange>* list_;
174
175 //- The index into the list
176 label index_;
177
178 //- Index of current element at list-index
179 label subIndex_;
180
181 public:
182
183 // Constructors
184
185 //- Construct from range list at given index (and sub-index)
186 inline explicit constexpr const_iterator
187 (
188 const UList<labelRange>* list,
189 const label idx = 0,
190 const label subIdx = 0
191 ) noexcept;
192
193
194 // Member Operators
196 //- Return the current label
197 inline label operator*() const;
198
199 inline const_iterator& operator++();
200 inline const_iterator operator++(int);
201
202 inline constexpr bool operator==(const const_iterator& iter)
203 const noexcept;
204
205 inline constexpr bool operator!=(const const_iterator& iter)
206 const noexcept;
207 };
208
209
210 //- A const_iterator set to the beginning of the list
211 inline const_iterator cbegin() const noexcept;
212
213 //- A const_iterator set to beyond the end of the list
214 inline const const_iterator cend() const noexcept;
215
216 //- A const_iterator set to the beginning of the list
217 inline const_iterator begin() const noexcept;
218
219 //- A const_iterator set to beyond the end of the list
220 inline const const_iterator end() const noexcept;
222
223 //- Return const_iterator at linear offset i from begin,
224 //- clamped to [0,size] range
225 inline const_iterator cbegin(const label i) const;
226
227 //- Return const_iterator at linear offset i from begin,
228 //- clamped to [0,size] range
229 inline const_iterator begin(const label i) const;
230
231
232 // Reading/writing
233
234 //- Read List of labelRange from Istream, discarding contents
236
237 //- Write List of labelRange, with line-breaks in ASCII
238 //- when length exceeds shortLen.
239 // Using '0' suppresses line-breaks entirely.
240 Ostream& writeList(Ostream& os, const label shortLen=0) const;
241
242
243 // IOstream Operators
244
245 //- Use the readList() method to read contents from Istream.
246 friend Istream& operator>>(Istream& is, labelRanges& list);
247
248 //- Write to Ostream. Uses the writeList() method
249 friend Ostream& operator<<(Ostream& os, const labelRanges& list);
250
251
252 // Housekeeping
253
254 //- Same as contains()
255 bool found(const label value) const { return contains(value); }
256};
257
258
259// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260
261} // End namespace Foam
262
263// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264
265#include "labelRangesI.H"
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269#endif
270
271// ************************************************************************* //
scalar range
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
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
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
Forward input iterator with const access.
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).
A list of labelRange with constrained list capabilities.
Definition labelRanges.H:55
void clear() noexcept
Clear the addressable list of ranges.
bool remove(const labelRange &range)
Remove the range from the list.
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List of labelRange, with line-breaks in ASCII when length exceeds shortLen.
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.
labelRanges(labelRanges &&)=default
Default move construct.
Istream & readList(Istream &is)
Read List of labelRange from Istream, discarding contents.
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the list.
labelRanges(const labelRanges &)=default
Default copy construct.
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.
labelRanges(Istream &is)
Construct from Istream.
bool empty() const noexcept
True if list of ranges is empty.
bool found(const label value) const
Same as contains().
void sort()
Inplace sort of the range elements.
const UList< labelRange > & ranges() const noexcept
The list of ranges.
const const_iterator cend() const noexcept
A const_iterator set to beyond the end of the list.
bool add(const labelRange &range)
Add the range to the list.
labelRanges & operator=(labelRanges &&)=default
Default move assignment.
const const_iterator end() const noexcept
A const_iterator set to beyond the end of the list.
void reserve(const label len)
Reserve space for at least this size.
List< label > labels() const
Return flattened list of all range labels.
labelRanges & operator=(const labelRanges &)=default
Default copy assignment.
labelRange value_type
The value type the list contains.
Definition labelRanges.H:83
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition eddy.H:297
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition scalarImpl.H:265
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Foam::argList args(argc, argv)