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-2020 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.
32
33SourceFiles
34 labelRanges.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef labelRanges_H
39#define labelRanges_H
40
41#include "labelRange.H"
42#include "DynamicList.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48
49// Forward Declarations
50class Istream;
51class Ostream;
52class labelRanges;
53Istream& operator>>(Istream& is, labelRanges& ranges);
54Ostream& operator<<(Ostream& is, const labelRanges& ranges);
55
56/*---------------------------------------------------------------------------*\
57 Class labelRanges Declaration
58\*---------------------------------------------------------------------------*/
60class labelRanges
61:
62 private Foam::DynamicList<Foam::labelRange>
63{
64 // Private Typedefs
65
67
68
69 // Private Member Functions
70
71 //- Insert range before specified insertion index, by copying up
72 void insertBefore(const label insert, const labelRange& range);
73
74 //- Purge empty ranges, by copying down
75 void purgeEmpty();
76
77public:
78
79 // STL type definitions
80
81 //- Input iterator with const access
82 class const_iterator;
83
84
85 // Constructors
86
87 //- Default construct
88 labelRanges() = default;
89
90 //- Construct given size
91 inline explicit labelRanges(const label nElem);
92
93 //- Construct from Istream.
95
96
97 // Member Functions
98
99 //- Clear the addressed list
101
102 //- Return true if the list is empty
104
105 //- Return true if the value is found any of the sub-ranges
106 inline bool found(const label value) const;
107
108 //- Add the range to the list
109 bool add(const labelRange& range);
110
111 //- Remove the range from the list
112 bool remove(const labelRange& range);
113
114
115 // STL iterator
116
117 //- Forward input iterator with const access
118 class const_iterator
119 {
120 //- The list for which this is an iterator
121 const labelRanges* list_;
122
123 //- The index into the list
124 label index_;
125
126 //- Index of current element at list-index
127 label subIndex_;
128
129 public:
130
131 // Constructors
132
133 //- Construct from range list at given index
134 inline explicit constexpr const_iterator
135 (
136 const labelRanges* list,
137 const label i = 0
138 ) noexcept;
139
140
141 // Member Operators
142
143 //- Return the current label
144 inline label operator*() const;
145
146 inline const_iterator& operator++();
147 inline const_iterator operator++(int);
148
149 inline constexpr bool operator==(const const_iterator& iter)
150 const noexcept;
151
152 inline constexpr bool operator!=(const const_iterator& iter)
153 const noexcept;
154 };
155
156
157 //- A const_iterator set to the beginning of the list
158 inline const_iterator cbegin() const noexcept;
159
160 //- A const_iterator set to beyond the end of the list
161 inline const const_iterator cend() const noexcept;
162
163 //- A const_iterator set to the beginning of the list
164 inline const_iterator begin() const noexcept;
165
166 //- A const_iterator set to beyond the end of the list
167 inline const const_iterator end() const noexcept;
168
169
170 // IOstream Operators
172 friend Istream& operator>>(Istream& is, labelRanges& ranges);
173 friend Ostream& operator<<(Ostream& os, const labelRanges& ranges);
174};
175
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178
179} // End namespace Foam
180
181// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182
183#include "labelRangesI.H"
184
185// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186
187#endif
188
189// ************************************************************************* //
scalar range
bool found
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::labelRange remove()
Remove and return the last element. Fatal on an empty list.
Definition: DynamicListI.H:655
friend Ostream & operator(Ostream &os, const DynamicList< Foam::labelRange, 16 > &list)
Write to Ostream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
Forward input iterator with const access.
Definition: labelRanges.H:118
constexpr bool operator==(const const_iterator &iter) const noexcept
Definition: labelRangesI.H:87
label operator*() const
Return the current label.
Definition: labelRangesI.H:53
constexpr bool operator!=(const const_iterator &iter) const noexcept
Definition: labelRangesI.H:102
A list of labelRange.
Definition: labelRanges.H:62
labelRanges()=default
Default construct.
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the list.
Definition: labelRangesI.H:113
const_iterator begin() const noexcept
A const_iterator set to the beginning of the list.
Definition: labelRangesI.H:127
const const_iterator cend() const noexcept
A const_iterator set to beyond the end of the list.
Definition: labelRangesI.H:120
bool add(const labelRange &range)
Add the range to the list.
Definition: labelRanges.C:136
const const_iterator end() const noexcept
A const_iterator set to beyond the end of the list.
Definition: labelRangesI.H:134
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition: Scalar.H:223
srcOptions insert("case", fileName(rootDirSource/caseDirSource))