ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / ranges / labelRange / labelRangeI.H
blobeaafd563f3bd3d1074e769c5f649e973a4e0eba9
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.
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
29 inline Foam::labelRange::labelRange()
31     start_(0),
32     size_(0)
36 inline Foam::labelRange::labelRange(const label start, const label size)
38     start_(start),
39     size_(size)
41     // disallow invalid sizes
42     if (size_ <= 0)
43     {
44         this->clear();
45     }
49 // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
51 inline Foam::labelRange::const_iterator::const_iterator()
53    range_(*reinterpret_cast< Foam::labelRange* >(0)),
54    index_(-1)
58 inline Foam::labelRange::const_iterator::const_iterator(const labelRange& range)
60    range_(range),
61    index_(range_.empty() ? -1 : 0)
65 inline bool Foam::labelRange::const_iterator::operator==
67     const const_iterator& iter
68 ) const
70     return (this->index_ == iter.index_);
74 inline bool Foam::labelRange::const_iterator::operator!=
76     const const_iterator& iter
77 ) const
79     return !(this->operator==(iter));
83 inline Foam::label Foam::labelRange::const_iterator::operator*()
85     return range_[index_];
89 inline Foam::label Foam::labelRange::const_iterator::operator()()
91     return range_[index_];
95 inline Foam::labelRange::const_iterator&
96 Foam::labelRange::const_iterator::operator++()
98     if (++index_ >= range_.size())
99     {
100         // equivalent to end iterator
101         index_ = -1;
102     }
104     return *this;
108 inline Foam::labelRange::const_iterator
109 Foam::labelRange::const_iterator::operator++(int)
111     const_iterator old = *this;
112     this->operator++();
113     return old;
117 inline Foam::labelRange::const_iterator Foam::labelRange::cbegin() const
119     return const_iterator(*this);
123 inline const Foam::labelRange::const_iterator& Foam::labelRange::cend() const
125     return endIter_;
129 inline Foam::labelRange::const_iterator Foam::labelRange::begin() const
131     return const_iterator(*this);
135 inline const Foam::labelRange::const_iterator& Foam::labelRange::end() const
137     return endIter_;
141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
143 inline void Foam::labelRange::clear()
145     start_ = size_ = 0;
149 inline bool Foam::labelRange::empty() const
151     return !size_;
155 inline Foam::label Foam::labelRange::size() const
157     return size_;
161 inline Foam::label Foam::labelRange::first() const
163     return start_;
167 inline Foam::label Foam::labelRange::last() const
169     return start_ + size_ - 1;
173 inline bool Foam::labelRange::contains(const label value) const
175     return value >= this->first() && value <= this->last();
179 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
181 inline Foam::label Foam::labelRange::operator[](const label i) const
183     return start_ + i;
187 inline bool Foam::labelRange::operator<(const labelRange& rhs) const
189     return this->first() < rhs.first();
193 inline bool Foam::labelRange::operator==(const labelRange& rhs) const
195     return start_ == rhs.start_ && size_ == rhs.size_;
199 inline bool Foam::labelRange::operator!=(const labelRange& rhs) const
201     return !(operator==(rhs));
205 // ************************************************************************* //