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