1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A label range specifier.
33 \*---------------------------------------------------------------------------*/
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // Forward declaration of classes
48 // Forward declaration of friend functions and operators
50 Istream& operator>>(Istream&, labelRange&);
51 Ostream& operator<<(Ostream&, const labelRange&);
53 /*---------------------------------------------------------------------------*\
54 Class labelRange Declaration
55 \*---------------------------------------------------------------------------*/
71 //- Less function class for sorting labelRange
76 bool operator()(const labelRange& a, const labelRange& b)
78 return a.first() < b.first();
84 //- Construct an empty range
88 // A negative size is autmatically changed to zero.
89 inline labelRange(const label start, const label size);
91 //- Construct from Istream.
97 //- Reset to zero size
100 //- Is the range empty?
101 inline bool empty() const;
103 //- Return the effective size of the range
104 inline label size() const;
106 //- The (inclusive) lower value of the range
107 inline label first() const;
109 //- The (inclusive) upper value of the range
110 inline label last() const;
112 //- Return true if the value is within the range
113 inline bool contains(const label) const;
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;
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;
126 //- Return element in range, no bounds checking
127 inline label operator[](const label) const;
129 //- Comparison function for sorting, compares the start
130 inline bool operator<(const labelRange& rhs) const;
132 //- Join ranges, squashing any gaps in between
133 // A prior intersects() check can be used to avoid squashing gaps.
134 labelRange& operator+=(const labelRange&);
136 inline bool operator==(const labelRange&) const;
137 inline bool operator!=(const labelRange&) const;
142 //- An STL const_iterator
147 //- Reference to the range for which this is an iterator
148 const labelRange& range_;
157 //- Construct null - equivalent to an 'end' position
158 inline const_iterator();
160 //- Construct from range, moving to its 'begin' position
161 inline explicit const_iterator(const labelRange&);
166 inline bool operator==(const const_iterator&) const;
168 inline bool operator!=(const const_iterator&) const;
170 inline label operator*();
171 inline label operator()();
173 inline const_iterator& operator++();
174 inline const_iterator operator++(int);
178 //- const_iterator set to the beginning of the range
179 inline const_iterator cbegin() const;
181 //- const_iterator set to beyond the end of the range
182 inline const const_iterator& cend() const;
184 //- const_iterator set to the beginning of the range
185 inline const_iterator begin() const;
187 //- const_iterator set to beyond the end of the range
188 inline const const_iterator& end() const;
191 // IOstream Operators
193 friend Istream& operator>>(Istream&, labelRange&);
194 friend Ostream& operator<<(Ostream&, const labelRange&);
199 //- const_iterator returned by end(), cend()
200 static const const_iterator endIter_;
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 } // End namespace Foam
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 #include "labelRangeI.H"
215 // ************************************************************************* //