1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
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/>.
33 \*---------------------------------------------------------------------------*/
38 #include "labelRange.H"
39 #include "DynamicList.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // Forward declaration of classes
50 // Forward declaration of friend functions and operators
52 Istream& operator>>(Istream&, labelRanges&);
53 Ostream& operator<<(Ostream&, const labelRanges&);
55 /*---------------------------------------------------------------------------*\
56 Class labelRanges Declaration
57 \*---------------------------------------------------------------------------*/
61 private DynamicList<labelRange>
63 // Private typedefs for convenience
65 typedef DynamicList<labelRange> ParentType;
68 // Private Member Functions
70 //- Insert range before specified insertion index, by copying up
71 void insertBefore(const label, const labelRange&);
73 //- Purge empty ranges, by copying down
76 //- Print the range for debugging purposes
77 Ostream& printRange(Ostream&, const labelRange&) const;
87 //- Construct given size
88 inline explicit labelRanges(const label);
90 //- Construct from Istream.
91 labelRanges(Istream&);
96 //- Clear the addressed list
97 using DynamicList<labelRange>::clear;
99 //- Return true if the list is empty
100 using DynamicList<labelRange>::empty;
102 //- Return true if the value is within any of the ranges
103 inline bool contains(const label) const;
105 //- Add the range to the list
106 bool add(const labelRange&);
108 //- Remove the range from the list
109 bool remove(const labelRange&);
113 //- An STL const_iterator
118 //- Reference to the list for which this is an iterator
119 const labelRanges& list_;
121 //- Current list index
124 //- Index of current element at listIndex
131 //- Construct null - equivalent to an 'end' position
132 inline const_iterator();
134 //- Construct from list, moving to its 'begin' position
135 inline explicit const_iterator(const labelRanges&);
140 inline bool operator==(const const_iterator&) const;
142 inline bool operator!=(const const_iterator&) const;
144 inline label operator*();
145 inline label operator()();
147 inline const_iterator& operator++();
148 inline const_iterator operator++(int);
152 //- const_iterator set to the beginning of the list
153 inline const_iterator cbegin() const;
155 //- const_iterator set to beyond the end of the list
156 inline const const_iterator& cend() const;
158 //- const_iterator set to the beginning of the list
159 inline const_iterator begin() const;
161 //- const_iterator set to beyond the end of the list
162 inline const const_iterator& end() const;
165 // IOstream Operators
167 friend Istream& operator>>(Istream&, labelRanges&);
168 friend Ostream& operator<<(Ostream&, const labelRanges&);
173 //- const_iterator returned by end(), cend()
174 static const const_iterator endIter_;
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 } // End namespace Foam
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 #include "labelRangesI.H"
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 // ************************************************************************* //