labelRange.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 | Copyright (C) 2011 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 #ifndef labelRange_H
35 #define labelRange_H
36 
37 #include "label.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // Forward declaration of classes
45 class Istream;
46 class Ostream;
47 
48 // Forward declaration of friend functions and operators
49 class labelRange;
50 Istream& operator>>(Istream&, labelRange&);
51 Ostream& operator<<(Ostream&, const labelRange&);
52 
53 /*---------------------------------------------------------------------------*\
54  Class labelRange Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class labelRange
58 {
59  // Private data
60 
61  label start_;
62  label size_;
63 
64 public:
65 
66  static int debug;
67 
68 
69  // Public classes
70 
71  //- Less function class for sorting labelRange
72  class less
73  {
74  public:
75 
76  bool operator()(const labelRange& a, const labelRange& b)
77  {
78  return a.first() < b.first();
79  }
80  };
81 
82  // Constructors
83 
84  //- Construct an empty range
85  inline labelRange();
86 
87  //- Construct a range
88  // A negative size is autmatically changed to zero.
89  inline labelRange(const label start, const label size);
90 
91  //- Construct from Istream.
93 
94 
95  // Member Functions
96 
97  //- Reset to zero size
98  inline void clear();
99 
100  //- Is the range empty?
101  inline bool empty() const;
102 
103  //- Return the effective size of the range
104  inline label size() const;
105 
106  //- The (inclusive) lower value of the range
107  inline label first() const;
108 
109  //- The (inclusive) upper value of the range
110  inline label last() const;
111 
112  //- Return true if the value is within the range
113  inline bool contains(const label) const;
114 
115  //- Return true if the ranges intersect
116  // Optional test for ranges that also just touch each other
117  bool intersects(const labelRange&, const bool touches = false) const;
118 
119  //- Return a joined range, squashing any gaps in between
120  // A prior intersects() check can be used to avoid squashing gaps.
121  labelRange join(const labelRange&) const;
122 
123 
124  // Member Operators
125 
126  //- Return element in range, no bounds checking
127  inline label operator[](const label) const;
128 
129  //- Comparison function for sorting, compares the start
130  inline bool operator<(const labelRange& rhs) const;
131 
132  //- Join ranges, squashing any gaps in between
133  // A prior intersects() check can be used to avoid squashing gaps.
135 
136  inline bool operator==(const labelRange&) const;
137  inline bool operator!=(const labelRange&) const;
138 
139 
140  // STL iterator
141 
142  //- An STL const_iterator
143  class const_iterator
144  {
145  // Private data
146 
147  //- Reference to the range for which this is an iterator
148  const labelRange& range_;
149 
150  //- Current index
151  label index_;
152 
153  public:
154 
155  // Constructors
156 
157  //- Construct null - equivalent to an 'end' position
158  inline const_iterator();
159 
160  //- Construct from range, moving to its 'begin' position
161  inline explicit const_iterator(const labelRange&);
162 
163 
164  // Member operators
165 
166  inline bool operator==(const const_iterator&) const;
167 
168  inline bool operator!=(const const_iterator&) const;
169 
170  inline label operator*();
171  inline label operator()();
172 
173  inline const_iterator& operator++();
174  inline const_iterator operator++(int);
175  };
176 
177 
178  //- const_iterator set to the beginning of the range
179  inline const_iterator cbegin() const;
180 
181  //- const_iterator set to beyond the end of the range
182  inline const const_iterator& cend() const;
183 
184  //- const_iterator set to the beginning of the range
185  inline const_iterator begin() const;
186 
187  //- const_iterator set to beyond the end of the range
188  inline const const_iterator& end() const;
189 
190 
191  // IOstream Operators
192 
193  friend Istream& operator>>(Istream&, labelRange&);
194  friend Ostream& operator<<(Ostream&, const labelRange&);
195 
196 
197 private:
198 
199  //- const_iterator returned by end(), cend()
200  static const const_iterator endIter_;
201 
202 };
203 
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 } // End namespace Foam
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 #include "labelRangeI.H"
212 
213 #endif
214 
215 // ************************************************************************* //
Less function class for sorting labelRange.
Definition: labelRange.H:71
tmp< fvMatrix< Type > > operator*(const DimensionedField< scalar, volMesh > &, const fvMatrix< Type > &)
bool operator==(const labelRange &) const
Definition: labelRangeI.H:193
label size() const
Return the effective size of the range.
Definition: labelRangeI.H:155
const_iterator cbegin() const
const_iterator set to the beginning of the range
Definition: labelRangeI.H:117
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
bool operator<(const labelRange &rhs) const
Comparison function for sorting, compares the start.
Definition: labelRangeI.H:187
labelRange join(const labelRange &) const
Return a joined range, squashing any gaps in between.
Definition: labelRange.C:78
const const_iterator & end() const
const_iterator set to beyond the end of the range
Definition: labelRangeI.H:135
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
labelRange()
Construct an empty range.
Definition: labelRangeI.H:29
A label range specifier.
Definition: labelRange.H:56
An STL const_iterator.
Definition: labelRange.H:142
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
void clear()
Reset to zero size.
Definition: labelRangeI.H:143
label operator[](const label) const
Return element in range, no bounds checking.
Definition: labelRangeI.H:181
labelRange & operator+=(const labelRange &)
Join ranges, squashing any gaps in between.
Definition: labelRange.C:100
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Namespace for OpenFOAM.
bool empty() const
Is the range empty?
Definition: labelRangeI.H:149
bool operator!=(const labelRange &) const
Definition: labelRangeI.H:199
label last() const
The (inclusive) upper value of the range.
Definition: labelRangeI.H:167
bool operator()(const labelRange &a, const labelRange &b)
Definition: labelRange.H:75
bool intersects(const labelRange &, const bool touches=false) const
Return true if the ranges intersect.
Definition: labelRange.C:51
bool contains(const label) const
Return true if the value is within the range.
Definition: labelRangeI.H:173
label first() const
The (inclusive) lower value of the range.
Definition: labelRangeI.H:161
const_iterator begin() const
const_iterator set to the beginning of the range
Definition: labelRangeI.H:129
friend Istream & operator>>(Istream &, labelRange &)
friend Ostream & operator<<(Ostream &, const labelRange &)
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const const_iterator & cend() const
const_iterator set to beyond the end of the range
Definition: labelRangeI.H:123
static int debug
Definition: labelRange.H:65