labelRanges.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::labelRanges
29 
30 Description
31  A list of labelRange.
32 
33 SourceFiles
34  labelRanges.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef labelRanges_H
39 #define labelRanges_H
40 
41 #include "labelRange.H"
42 #include "DynamicList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 class Istream;
51 class Ostream;
52 
53 // Forward declaration of friend functions and operators
54 class labelRanges;
55 Istream& operator>>(Istream& is, labelRanges& ranges);
56 Ostream& operator<<(Ostream& is, const labelRanges& ranges);
57 
58 /*---------------------------------------------------------------------------*\
59  Class labelRanges Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class labelRanges
63 :
64  private DynamicList<labelRange>
65 {
66  // Private typedefs for convenience
67 
69 
70 
71  // Private Member Functions
72 
73  //- Insert range before specified insertion index, by copying up
74  void insertBefore(const label insert, const labelRange& range);
75 
76  //- Purge empty ranges, by copying down
77  void purgeEmpty();
78 
79  //- Print the range for debugging purposes
80  Ostream& printRange(Ostream& os, const labelRange& range) const;
81 
82 
83 public:
84 
85  // Constructors
86 
87  //- Construct null
88  inline labelRanges();
89 
90  //- Construct given size
91  inline explicit labelRanges(const label nElem);
92 
93  //- Construct from Istream.
94  labelRanges(Istream& is);
95 
96 
97  // Member Functions
98 
99  //- Clear the addressed list
101 
102  //- Return true if the list is empty
104 
105  //- Return true if the value is found any of the sub-ranges
106  inline bool found(const label value) const;
107 
108  //- Add the range to the list
109  bool add(const labelRange& range);
110 
111  //- Remove the range from the list
112  bool remove(const labelRange& range);
113 
114 
115  // STL iterator
116 
117  //- An STL const_iterator
118  class const_iterator
119  {
120  friend class labelRanges;
121 
122  // Private data
123 
124  //- Reference to the list for which this is an iterator
125  const labelRanges* list_;
126 
127  //- Current list-index
128  label index_;
129 
130  //- Index of current element at list-index
131  label subIndex_;
132 
133  // Constructors
134 
135  //- Construct from ranges at given index.
136  // A negative index signals the 'end' position
137  inline const_iterator(const labelRanges* lst, const label i);
138 
139  public:
140 
141  // Member operators
142 
143  inline bool operator==(const const_iterator& iter) const;
144  inline bool operator!=(const const_iterator& iter) const;
145 
146  //- Return the current label
147  inline label operator*();
148 
149  inline const_iterator& operator++();
150  inline const_iterator operator++(int);
151  };
152 
153 
154  //- A const_iterator set to the beginning of the list
155  inline const_iterator cbegin() const;
156 
157  //- A const_iterator set to beyond the end of the list
158  inline const const_iterator cend() const;
159 
160  //- A const_iterator set to the beginning of the list
161  inline const_iterator begin() const;
162 
163  //- A const_iterator set to beyond the end of the list
164  inline const const_iterator end() const;
165 
166 
167  // IOstream Operators
168 
169  friend Istream& operator>>(Istream& is, labelRanges& ranges);
170  friend Ostream& operator<<(Ostream& os, const labelRanges& ranges);
171 
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 } // End namespace Foam
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #include "labelRangesI.H"
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #endif
186 
187 // ************************************************************************* //
Foam::labelRanges::found
bool found(const label value) const
Return true if the value is found any of the sub-ranges.
Definition: labelRangesI.H:135
insert
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Foam::labelRanges::operator<<
friend Ostream & operator<<(Ostream &os, const labelRanges &ranges)
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::labelRanges::const_iterator::operator++
const_iterator & operator++()
Definition: labelRangesI.H:87
Foam::labelRanges::end
const const_iterator end() const
A const_iterator set to beyond the end of the list.
Definition: labelRangesI.H:127
Foam::labelRanges::labelRanges
labelRanges()
Construct null.
Definition: labelRangesI.H:32
Foam::labelRanges::add
bool add(const labelRange &range)
Add the range to the list.
Definition: labelRanges.C:126
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
labelRangesI.H
Foam::labelRanges::const_iterator::operator!=
bool operator!=(const const_iterator &iter) const
Definition: labelRangesI.H:72
Foam::labelRanges::const_iterator
An STL const_iterator.
Definition: labelRanges.H:117
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::labelRanges
A list of labelRange.
Definition: labelRanges.H:61
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
Foam::labelRanges::begin
const_iterator begin() const
A const_iterator set to the beginning of the list.
Definition: labelRangesI.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::labelRanges::cbegin
const_iterator cbegin() const
A const_iterator set to the beginning of the list.
Definition: labelRangesI.H:109
labelRange.H
Foam::labelRanges::const_iterator::operator*
label operator*()
Return the current label.
Definition: labelRangesI.H:80
Foam::DynamicList< labelRange >::remove
labelRange remove()
Remove and return the last element. Fatal on an empty list.
Definition: DynamicListI.H:651
DynamicList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::labelRanges::operator>>
friend Istream & operator>>(Istream &is, labelRanges &ranges)
Foam::labelRanges::cend
const const_iterator cend() const
A const_iterator set to beyond the end of the list.
Definition: labelRangesI.H:115
Foam::labelRanges::const_iterator::operator==
bool operator==(const const_iterator &iter) const
Definition: labelRangesI.H:59