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 | Copyright (C) 2011 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 Class
25  Foam::labelRanges
26 
27 Description
28  A list of labelRange.
29 
30 SourceFiles
31  labelRanges.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef labelRanges_H
36 #define labelRanges_H
37 
38 #include "labelRange.H"
39 #include "DynamicList.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of classes
47 class Istream;
48 class Ostream;
49 
50 // Forward declaration of friend functions and operators
51 class labelRanges;
52 Istream& operator>>(Istream&, labelRanges&);
53 Ostream& operator<<(Ostream&, const labelRanges&);
54 
55 /*---------------------------------------------------------------------------*\
56  Class labelRanges Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class labelRanges
60 :
61  private DynamicList<labelRange>
62 {
63  // Private typedefs for convenience
64 
66 
67 
68  // Private Member Functions
69 
70  //- Insert range before specified insertion index, by copying up
71  void insertBefore(const label, const labelRange&);
72 
73  //- Purge empty ranges, by copying down
74  void purgeEmpty();
75 
76  //- Print the range for debugging purposes
77  Ostream& printRange(Ostream&, const labelRange&) const;
78 
79 
80 public:
81 
82  // Constructors
83 
84  //- Construct null
85  inline labelRanges();
86 
87  //- Construct given size
88  inline explicit labelRanges(const label);
89 
90  //- Construct from Istream.
92 
93 
94  // Member Functions
95 
96  //- Clear the addressed list
98 
99  //- Return true if the list is empty
101 
102  //- Return true if the value is within any of the ranges
103  inline bool contains(const label) const;
104 
105  //- Add the range to the list
106  bool add(const labelRange&);
107 
108  //- Remove the range from the list
109  bool remove(const labelRange&);
110 
111  // STL iterator
112 
113  //- An STL const_iterator
114  class const_iterator
115  {
116  // Private data
117 
118  //- Reference to the list for which this is an iterator
119  const labelRanges& list_;
120 
121  //- Current list index
122  label index_;
123 
124  //- Index of current element at listIndex
125  label subIndex_;
126 
127  public:
128 
129  // Constructors
130 
131  //- Construct null - equivalent to an 'end' position
132  inline const_iterator();
133 
134  //- Construct from list, moving to its 'begin' position
135  inline explicit const_iterator(const labelRanges&);
136 
137 
138  // Member operators
139 
140  inline bool operator==(const const_iterator&) const;
141 
142  inline bool operator!=(const const_iterator&) const;
143 
144  inline label operator*();
145  inline label operator()();
146 
147  inline const_iterator& operator++();
148  inline const_iterator operator++(int);
149  };
150 
151 
152  //- const_iterator set to the beginning of the list
153  inline const_iterator cbegin() const;
154 
155  //- const_iterator set to beyond the end of the list
156  inline const const_iterator& cend() const;
157 
158  //- const_iterator set to the beginning of the list
159  inline const_iterator begin() const;
160 
161  //- const_iterator set to beyond the end of the list
162  inline const const_iterator& end() const;
163 
164 
165  // IOstream Operators
166 
168  friend Ostream& operator<<(Ostream&, const labelRanges&);
169 
170 
171 private:
172 
173  //- const_iterator returned by end(), cend()
174  static const const_iterator endIter_;
175 
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #include "labelRangesI.H"
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
bool add(const labelRange &)
Add the range to the list.
Definition: labelRanges.C:127
const_iterator()
Construct null - equivalent to an 'end' position.
Definition: labelRangesI.H:43
An STL const_iterator.
Definition: labelRanges.H:113
A list of labelRange.
Definition: labelRanges.H:58
labelRanges()
Construct null.
Definition: labelRangesI.H:29
const_iterator begin() const
const_iterator set to the beginning of the list
Definition: labelRangesI.H:138
bool operator==(const const_iterator &) const
Definition: labelRangesI.H:66
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A label range specifier.
Definition: labelRange.H:56
const const_iterator & cend() const
const_iterator set to beyond the end of the list
Definition: labelRangesI.H:132
const const_iterator & end() const
const_iterator set to beyond the end of the list
Definition: labelRangesI.H:144
friend Ostream & operator<<(Ostream &, const labelRanges &)
const_iterator cbegin() const
const_iterator set to the beginning of the list
Definition: labelRangesI.H:126
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
friend Istream & operator>>(Istream &, labelRanges &)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
bool operator!=(const const_iterator &) const
Definition: labelRangesI.H:79
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
bool contains(const label) const
Return true if the value is within any of the ranges.
Definition: labelRangesI.H:152