1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "labelRange.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 const Foam::labelRange::const_iterator Foam::labelRange::endIter_;
34 int Foam::labelRange::debug(::Foam::debug::debugSwitch("labelRange", 0));
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 Foam::labelRange::labelRange(Istream& is)
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 bool Foam::labelRange::intersects
52 const labelRange& range,
56 label final = touches ? 1 : 0;
65 range.first() >= this->first()
66 && range.first() <= this->last() + final
70 this->first() >= range.first()
71 && this->first() <= range.last() + final
78 Foam::labelRange Foam::labelRange::join(const labelRange& range) const
80 // trivial cases first
85 else if (!range.size_)
90 const label lower = Foam::min(this->first(), range.first());
91 const label upper = Foam::max(this->last(), range.last());
92 const label sz = upper - lower + 1;
94 return labelRange(lower, sz);
98 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
100 Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs)
109 const label lower = Foam::min(this->first(), rhs.first());
110 const label upper = Foam::max(this->last(), rhs.last());
113 size_ = upper - lower + 1;
120 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
122 Foam::Istream& Foam::operator>>(Istream& is, labelRange& range)
124 is.readBegin("labelRange");
125 is >> range.start_ >> range.size_;
126 is.readEnd("labelRange");
128 is.check("operator>>(Istream&, labelRange&)");
130 // disallow invalid sizes
131 if (range.size_ <= 0)
140 Foam::Ostream& Foam::operator<<(Ostream& os, const labelRange& range)
142 // write ASCII only for now
143 os << token::BEGIN_LIST
144 << range.start_ << token::SPACE << range.size_
147 // os << token::BEGIN_BLOCK
148 // << range.start_ << "-" << range.last()
149 // << token::END_BLOCK;
151 os.check("operator<<(Ostream&, const labelRange&)");
156 // ************************************************************************* //