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 -------------------------------------------------------------------------------
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 labelRanges_H
39 #define labelRanges_H
40 
41 #include "labelRange.H"
42 #include "DynamicList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 class Istream;
51 class Ostream;
52 class labelRanges;
53 Istream& operator>>(Istream& is, labelRanges& ranges);
54 Ostream& operator<<(Ostream& is, const labelRanges& ranges);
55 
56 /*---------------------------------------------------------------------------*\
57  Class labelRanges Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class 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 
77 public:
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.
94  labelRanges(Istream& is);
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
171 
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 // ************************************************************************* //
Foam::labelRanges::const_iterator::operator!=
constexpr bool operator!=(const const_iterator &iter) const noexcept
Definition: labelRangesI.H:102
Foam::labelRanges::found
bool found(const label value) const
Return true if the value is found any of the sub-ranges.
Definition: labelRangesI.H:140
insert
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Foam::labelRanges::labelRanges
labelRanges()=default
Default construct.
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::labelRanges::const_iterator::operator++
const_iterator & operator++()
Definition: labelRangesI.H:61
Foam::labelRanges::cend
const const_iterator cend() const noexcept
A const_iterator set to beyond the end of the list.
Definition: labelRangesI.H:120
Foam::labelRanges::add
bool add(const labelRange &range)
Add the range to the list.
Definition: labelRanges.C:136
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::DynamicList< Foam::labelRange >::operator
friend Ostream & operator(Ostream &os, const DynamicList< Foam::labelRange, 16 > &list)
Write to Ostream.
Foam::labelRanges::const_iterator::operator==
constexpr bool operator==(const const_iterator &iter) const noexcept
Definition: labelRangesI.H:87
Foam::labelRanges::begin
const_iterator begin() const noexcept
A const_iterator set to the beginning of the list.
Definition: labelRangesI.H:127
Foam::labelRanges::const_iterator::const_iterator
constexpr const_iterator(const labelRanges *list, const label i=0) noexcept
Construct from range list at given index.
Definition: labelRangesI.H:41
Foam::labelRanges::const_iterator
Forward input iterator with const access.
Definition: labelRanges.H:117
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::labelRanges::const_iterator::operator*
label operator*() const
Return the current label.
Definition: labelRangesI.H:53
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::labelRanges
A list of labelRange.
Definition: labelRanges.H:59
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:55
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::labelRanges::cbegin
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the list.
Definition: labelRangesI.H:113
range
scalar range
Definition: LISASMDCalcMethod1.H:12
labelRange.H
Foam::labelRanges::end
const const_iterator end() const noexcept
A const_iterator set to beyond the end of the list.
Definition: labelRangesI.H:134
Foam::DynamicList< Foam::labelRange >::remove
Foam::labelRange remove()
Remove and return the last element. Fatal on an empty list.
Definition: DynamicListI.H:704
DynamicList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56