labelRangeI.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-2018 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 \*---------------------------------------------------------------------------*/
25 
26 
27 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
28 
30 :
31  start_(0),
32  size_(0)
33 {}
34 
35 
36 inline Foam::labelRange::labelRange(const label start, const label size)
37 :
38  start_(start),
39  size_(size)
40 {
41  // disallow invalid sizes
42  if (size_ <= 0)
43  {
44  this->clear();
45  }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
50 
52 :
53  range_(endLabelRange_),
54  index_(-1)
55 {}
56 
57 
59 :
60  range_(range),
61  index_(range_.empty() ? -1 : 0)
62 {}
63 
64 
65 inline bool Foam::labelRange::const_iterator::operator==
66 (
67  const const_iterator& iter
68 ) const
69 {
70  return (this->index_ == iter.index_);
71 }
72 
73 
74 inline bool Foam::labelRange::const_iterator::operator!=
75 (
76  const const_iterator& iter
77 ) const
78 {
79  return !(this->operator==(iter));
80 }
81 
82 
84 {
85  return range_[index_];
86 }
87 
88 
90 {
91  return range_[index_];
92 }
93 
94 
97 {
98  if (++index_ >= range_.size())
99  {
100  // equivalent to end iterator
101  index_ = -1;
102  }
103 
104  return *this;
105 }
106 
107 
110 {
111  const_iterator old = *this;
112  this->operator++();
113  return old;
114 }
115 
116 
118 {
119  return const_iterator(*this);
120 }
121 
122 
124 {
125  return endIter_;
126 }
127 
128 
130 {
131  return const_iterator(*this);
132 }
133 
134 
136 {
137  return endIter_;
138 }
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
145  start_ = size_ = 0;
146 }
147 
148 
149 inline bool Foam::labelRange::empty() const
150 {
151  return !size_;
152 }
153 
154 
156 {
157  return size_;
158 }
159 
160 
162 {
163  return start_;
164 }
165 
166 
168 {
169  return start_ + size_ - 1;
170 }
171 
172 
173 inline bool Foam::labelRange::contains(const label value) const
174 {
175  return value >= this->first() && value <= this->last();
176 }
177 
178 
179 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
180 
182 {
183  return start_ + i;
184 }
185 
186 
187 inline bool Foam::labelRange::operator<(const labelRange& rhs) const
188 {
189  return this->first() < rhs.first();
190 }
191 
192 
193 inline bool Foam::labelRange::operator==(const labelRange& rhs) const
194 {
195  return start_ == rhs.start_ && size_ == rhs.size_;
196 }
197 
198 
199 inline bool Foam::labelRange::operator!=(const labelRange& rhs) const
200 {
201  return !(operator==(rhs));
202 }
203 
204 
205 // ************************************************************************* //
const_iterator cbegin() const
const_iterator set to the beginning of the range
Definition: labelRangeI.H:117
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
const_iterator()
Construct null - equivalent to an &#39;end&#39; position.
Definition: labelRangeI.H:51
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
label size() const
Return the effective size of the range.
Definition: labelRangeI.H:155
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
scalar range
const const_iterator & end() const
const_iterator set to beyond the end of the range
Definition: labelRangeI.H:135
labelRange()
Construct an empty range.
Definition: labelRangeI.H:29
bool operator!=(const labelRange &) const
Definition: labelRangeI.H:199
label operator[](const label) const
Return element in range, no bounds checking.
Definition: labelRangeI.H:181
const_iterator & operator++()
Definition: labelRangeI.H:96
label last() const
The (inclusive) upper value of the range.
Definition: labelRangeI.H:167
bool operator==(const const_iterator &) const
Definition: labelRangeI.H:66
An STL const_iterator.
Definition: labelRange.H:144
bool operator==(const labelRange &) const
Definition: labelRangeI.H:193
label first() const
The (inclusive) lower value of the range.
Definition: labelRangeI.H:161