All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
labelRange.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::labelRange
26 
27 Description
28  A label range specifier.
29 
30 SourceFiles
31  labelRange.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef labelRange_H
36 #define labelRange_H
37 
38 #include "label.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class Istream;
47 class Ostream;
48 
49 // Forward declaration of friend functions and operators
50 class labelRange;
51 Istream& operator>>(Istream&, labelRange&);
52 Ostream& operator<<(Ostream&, const labelRange&);
53 
54 /*---------------------------------------------------------------------------*\
55  Class labelRange Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class labelRange
59 {
60  // Private Data
61 
62  label start_;
63  label size_;
64 
65 public:
66 
67  static int debug;
68 
69 
70  // Public classes
71 
72  //- Less function class for sorting labelRange
73  class less
74  {
75  public:
76 
77  bool operator()(const labelRange& a, const labelRange& b)
78  {
79  return a.first() < b.first();
80  }
81  };
82 
83 
84  // Constructors
85 
86  //- Construct an empty range
87  inline labelRange();
88 
89  //- Construct a range
90  // A negative size is automatically changed to zero.
91  inline labelRange(const label start, const label size);
92 
93  //- Construct from Istream.
95 
96 
97  // Member Functions
98 
99  //- Reset to zero size
100  inline void clear();
101 
102  //- Is the range empty?
103  inline bool empty() const;
104 
105  //- Return the effective size of the range
106  inline label size() const;
107 
108  //- The (inclusive) lower value of the range
109  inline label first() const;
110 
111  //- The (inclusive) upper value of the range
112  inline label last() const;
113 
114  //- Return true if the value is within the range
115  inline bool contains(const label) const;
116 
117  //- Return true if the ranges intersect
118  // Optional test for ranges that also just touch each other
119  bool intersects(const labelRange&, const bool touches = false) const;
120 
121  //- Return a joined range, squashing any gaps in between
122  // A prior intersects() check can be used to avoid squashing gaps.
123  labelRange join(const labelRange&) const;
124 
125 
126  // Member Operators
127 
128  //- Return element in range, no bounds checking
129  inline label operator[](const label) const;
130 
131  //- Comparison function for sorting, compares the start
132  inline bool operator<(const labelRange& rhs) const;
133 
134  //- Join ranges, squashing any gaps in between
135  // A prior intersects() check can be used to avoid squashing gaps.
137 
138  inline bool operator==(const labelRange&) const;
139  inline bool operator!=(const labelRange&) const;
140 
141 
142  // STL iterator
143 
144  //- An STL const_iterator
145  class const_iterator
146  {
147  // Private Data
148 
149  //- Reference to the range for which this is an iterator
150  const labelRange& range_;
151 
152  //- Current index
153  label index_;
154 
155  public:
156 
157  // Constructors
158 
159  //- Construct null - equivalent to an 'end' position
160  inline const_iterator();
161 
162  //- Construct from range, moving to its 'begin' position
163  inline explicit const_iterator(const labelRange&);
164 
165 
166  // Member Operators
167 
168  inline bool operator==(const const_iterator&) const;
169 
170  inline bool operator!=(const const_iterator&) const;
171 
172  inline label operator*();
173  inline label operator()();
174 
175  inline const_iterator& operator++();
176  inline const_iterator operator++(int);
177  };
178 
179 
180  //- const_iterator set to the beginning of the range
181  inline const_iterator cbegin() const;
182 
183  //- const_iterator set to beyond the end of the range
184  inline const const_iterator& cend() const;
185 
186  //- const_iterator set to the beginning of the range
187  inline const_iterator begin() const;
188 
189  //- const_iterator set to beyond the end of the range
190  inline const const_iterator& end() const;
191 
192 
193  // IOstream Operators
194 
195  friend Istream& operator>>(Istream&, labelRange&);
196  friend Ostream& operator<<(Ostream&, const labelRange&);
197 
198 
199 private:
200 
201  //- const labelRange held by endIter_
202  static const labelRange endLabelRange_;
203 
204  //- const_iterator returned by end(), cend()
205  static const const_iterator endIter_;
206 };
207 
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 } // End namespace Foam
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #include "labelRangeI.H"
216 
217 #endif
218 
219 // ************************************************************************* //
const_iterator cbegin() const
const_iterator set to the beginning of the range
Definition: labelRangeI.H:117
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const const_iterator & cend() const
const_iterator set to beyond the end of the range
Definition: labelRangeI.H:123
bool contains(const label) const
Return true if the value is within the range.
Definition: labelRangeI.H:173
bool empty() const
Is the range empty?
Definition: labelRangeI.H:149
A label range specifier.
Definition: labelRange.H:57
void clear()
Reset to zero size.
Definition: labelRangeI.H:143
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Less function class for sorting labelRange.
Definition: labelRange.H:72
label size() const
Return the effective size of the range.
Definition: labelRangeI.H:155
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
static int debug
Definition: labelRange.H:66
bool operator<(const labelRange &rhs) const
Comparison function for sorting, compares the start.
Definition: labelRangeI.H:187
const_iterator begin() const
const_iterator set to the beginning of the range
Definition: labelRangeI.H:129
bool operator()(const labelRange &a, const labelRange &b)
Definition: labelRange.H:76
const const_iterator & end() const
const_iterator set to beyond the end of the range
Definition: labelRangeI.H:135
Istream & operator>>(Istream &, directionInfo &)
labelRange join(const labelRange &) const
Return a joined range, squashing any gaps in between.
Definition: labelRange.C:78
labelRange()
Construct an empty range.
Definition: labelRangeI.H:29
bool operator!=(const labelRange &) const
Definition: labelRangeI.H:199
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
label operator[](const label) const
Return element in range, no bounds checking.
Definition: labelRangeI.H:181
friend Ostream & operator<<(Ostream &, const labelRange &)
label last() const
The (inclusive) upper value of the range.
Definition: labelRangeI.H:167
labelRange & operator+=(const labelRange &)
Join ranges, squashing any gaps in between.
Definition: labelRange.C:100
An STL const_iterator.
Definition: labelRange.H:144
Ostream & operator<<(Ostream &, const ensightPart &)
bool operator==(const labelRange &) const
Definition: labelRangeI.H:193
bool intersects(const labelRange &, const bool touches=false) const
Return true if the ranges intersect.
Definition: labelRange.C:51
label first() const
The (inclusive) lower value of the range.
Definition: labelRangeI.H:161
Namespace for OpenFOAM.
friend Istream & operator>>(Istream &, labelRange &)