labelRangesI.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  ParentType()
32 {}
33 
34 
36 :
37  ParentType(nElem)
38 {}
39 
40 
41 // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
42 
44 :
45  list_(endLabelRanges_),
46  index_(-1),
47  subIndex_(-1)
48 {}
49 
50 
52 :
53  list_(lst),
54  index_(0),
55  subIndex_(0)
56 {
57  if (list_.empty())
58  {
59  // equivalent to end iterator
60  index_ = subIndex_ = -1;
61  }
62 }
63 
64 
65 inline bool Foam::labelRanges::const_iterator::operator==
66 (
67  const const_iterator& iter
68 ) const
69 {
70  return
71  (
72  this->index_ == iter.index_
73  && this->subIndex_ == iter.subIndex_
74  );
75 }
76 
77 
78 inline bool Foam::labelRanges::const_iterator::operator!=
79 (
80  const const_iterator& iter
81 ) const
82 {
83  return !(this->operator==(iter));
84 }
85 
86 
88 {
89  return list_[index_][subIndex_];
90 }
91 
92 
94 {
95  return list_[index_][subIndex_];
96 }
97 
98 
101 {
102  if (++subIndex_ >= list_[index_].size())
103  {
104  // go to next list entry
105  subIndex_ = 0;
106  if (++index_ >= list_.size())
107  {
108  // equivalent to end iterator
109  index_ = subIndex_ = -1;
110  }
111  }
112 
113  return *this;
114 }
115 
116 
119 {
120  const_iterator old = *this;
121  this->operator++();
122  return old;
123 }
124 
125 
127 {
128  return const_iterator(*this);
129 }
130 
131 
133 {
134  return endIter_;
135 }
136 
137 
139 {
140  return const_iterator(*this);
141 }
142 
143 
145 {
146  return endIter_;
147 }
148 
149 
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 
152 inline bool Foam::labelRanges::contains(const label value) const
153 {
154  forAll(*this, i)
155  {
156  if (this->ParentType::operator[](i).contains(value))
157  {
158  return true;
159  }
160  }
161 
162  return false;
163 }
164 
165 
166 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
labelRanges()
Construct null.
Definition: labelRangesI.H:29
const const_iterator & end() const
const_iterator set to beyond the end of the list
Definition: labelRangesI.H:144
const_iterator cbegin() const
const_iterator set to the beginning of the list
Definition: labelRangesI.H:126
bool contains(const label) const
Return true if the value is within any of the ranges.
Definition: labelRangesI.H:152
bool operator==(const const_iterator &) const
Definition: labelRangesI.H:66
const_iterator()
Construct null - equivalent to an &#39;end&#39; position.
Definition: labelRangesI.H:43
A list of labelRange.
Definition: labelRanges.H:58
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
const const_iterator & cend() const
const_iterator set to beyond the end of the list
Definition: labelRangesI.H:132
friend Ostream & operator(Ostream &, const DynamicList< labelRange, 0, 2, 1 > &)
An STL const_iterator.
Definition: labelRanges.H:113
const_iterator begin() const
const_iterator set to the beginning of the list
Definition: labelRangesI.H:138