ConstCirculator.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) 2012-2020 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::ConstCirculator
26 
27 Description
28  Walks over a container as if it were circular. The container must have the
29  following members defined:
30  - value_type
31  - size_type
32  - difference_type
33  - const_iterator
34  - const_reference
35 
36  Examples:
37 
38  \code
39  face f(identity(5));
40 
41  // Construct circulator from the face
42  ConstCirculator<face> circ(f);
43 
44  // First check that the circulator has a size to iterate over.
45  // Then circulate around the list starting and finishing at the fulcrum.
46  if (circ.size()) do
47  {
48  Info<< "Iterate forwards over face : " << circ() << endl;
49 
50  } while (circ.circulate(CirculatorBase::direction::clockwise));
51  \endcode
52 
53  \code
54  face f(identity(5));
55 
56  ConstCirculator<face> circClockwise(f);
57  ConstCirculator<face> circAnticlockwise(f);
58 
59  if (circClockwise.size() && circAnticlockwise.size()) do
60  {
61  Info<< "Iterate forward over face :" << circClockwise() << endl;
62  Info<< "Iterate backward over face:" << circAnticlockwise() << endl;
63  }
64  while
65  (
66  circClockwise.circulate(CirculatorBase::direction::clockwise),
67  circAnticlockwise.circulate
68  (
69  CirculatorBase::direction::anticlockwise
70  )
71  );
72  \endcode
73 
74 SourceFiles
75  ConstCirculatorI.H
76 
77 \*---------------------------------------------------------------------------*/
78 
79 #ifndef ConstCirculator_H
80 #define ConstCirculator_H
81 
82 #include "CirculatorBase.H"
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 namespace Foam
87 {
88 
89 
90 /*---------------------------------------------------------------------------*\
91  Class ConstCirculator Declaration
92 \*---------------------------------------------------------------------------*/
93 
94 template<class ContainerType>
95 class ConstCirculator
96 :
97  public CirculatorBase
98 {
99 
100 protected:
101 
102  // Protected data
103 
104  //- Iterator pointing to the beginning of the container
105  typename ContainerType::const_iterator begin_;
106 
107  //- Iterator pointing to the end of the container
108  typename ContainerType::const_iterator end_;
109 
110  //- Iterator
111  typename ContainerType::const_iterator iter_;
112 
113  //- Iterator holding the location of the fulcrum (start and end) of
114  // the container. Used to decide when the iterator should stop
115  // circulating over the container
116  typename ContainerType::const_iterator fulcrum_;
117 
118 
119 public:
120 
121  // STL type definitions
122 
123  //- Type of values ContainerType contains.
124  typedef typename ContainerType::value_type value_type;
125 
126  //- The type that can represent the size of ContainerType
127  typedef typename ContainerType::size_type size_type;
128 
129  //- The type that can represent the difference between any two
130  // iterator objects.
131  typedef typename ContainerType::difference_type difference_type;
132 
133  //- Random access iterator for traversing ContainerType.
134  typedef typename ContainerType::const_iterator const_iterator;
135 
136  //- Type that can be used for storing into
137  // const ContainerType::value_type objects.
138  typedef typename ContainerType::const_reference const_reference;
139 
140 
141  // Constructors
142 
143  //- Construct null
144  inline ConstCirculator();
145 
146  //- Construct from a container.
147  inline explicit ConstCirculator(const ContainerType& container);
148 
149  //- Construct from two iterators
150  inline ConstCirculator
151  (
152  const const_iterator& begin,
153  const const_iterator& end
154  );
155 
156  //- Copy constructor
158 
159 
160  //- Destructor
162 
163 
164  // Member Functions
165 
166  //- Return the range of the iterator
167  inline size_type size() const;
168 
169  //- Circulate around the list in the given direction
170  inline bool circulate
171  (
172  const CirculatorBase::direction dir =
174  );
175 
176  //- Set the fulcrum to the current position of the iterator
177  inline void setFulcrumToIterator();
178 
179  //- Set the iterator to the current position of the fulcrum
180  inline void setIteratorToFulcrum();
181 
182  //- Return the distance between the iterator and the fulcrum. This is
183  // equivalent to the number of rotations of the circulator.
184  inline difference_type nRotations() const;
185 
186  //- Dereference the next iterator and return
187  inline const_reference next() const;
188 
189  //- Dereference the previous iterator and return
190  inline const_reference prev() const;
191 
192 
193  // Member Operators
194 
195  //- Assignment operator for circulators that operate on the same
196  // container type
197  inline void operator=(const ConstCirculator<ContainerType>&);
198 
199  //- Prefix increment. Increments the iterator.
200  // Sets the iterator to the beginning of the container if it reaches
201  // the end
203 
204  //- Postfix increment. Increments the iterator.
205  // Sets the iterator to the beginning of the container if it reaches
206  // the end
208 
209  //- Prefix decrement. Decrements the iterator.
210  // Sets the iterator to the end of the container if it reaches
211  // the beginning
213 
214  //- Postfix decrement. Decrements the iterator.
215  // Sets the iterator to the end of the container if it reaches
216  // the beginning
218 
219  //- Check for equality of this iterator with another iterator that
220  // operate on the same container type
221  inline bool operator==(const ConstCirculator<ContainerType>& c) const;
222 
223  //- Check for inequality of this iterator with another iterator that
224  // operate on the same container type
225  inline bool operator!=(const ConstCirculator<ContainerType>& c) const;
226 
227  //- Dereference the iterator and return
228  inline const_reference operator*() const;
229 
230  //- Dereference the iterator and return
231  inline const_reference operator()() const;
232 
233  //- Return the difference between this iterator and another iterator
234  // that operate on the same container type
235  inline difference_type operator-
236  (
238  ) const;
239 };
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 } // End namespace Foam
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #include "ConstCirculatorI.H"
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #endif
253 
254 // ************************************************************************* //
ContainerType::const_iterator end_
Iterator pointing to the end of the container.
ContainerType::difference_type difference_type
The type that can represent the difference between any two.
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
direction
Direction type enumeration.
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
const_reference prev() const
Dereference the previous iterator and return.
~ConstCirculator()
Destructor.
const dimensionedScalar c
Speed of light in a vacuum.
ConstCirculator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
void operator=(const ConstCirculator< ContainerType > &)
Assignment operator for circulators that operate on the same.
ContainerType::const_iterator iter_
Iterator.
ContainerType::value_type value_type
Type of values ContainerType contains.
size_type size() const
Return the range of the iterator.
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
ConstCirculator()
Construct null.
bool operator==(const ConstCirculator< ContainerType > &c) const
Check for equality of this iterator with another iterator that.
ContainerType::const_iterator const_iterator
Random access iterator for traversing ContainerType.
ContainerType::const_iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
ContainerType::const_iterator begin_
Iterator pointing to the beginning of the container.
ConstCirculator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Base class for circulators.
bool circulate(const CirculatorBase::direction dir=CirculatorBase::direction::none)
Circulate around the list in the given direction.
const_reference operator*() const
Dereference the iterator and return.
const_reference operator()() const
Dereference the iterator and return.
const_reference next() const
Dereference the next iterator and return.
ContainerType::const_reference const_reference
Type that can be used for storing into.
Walks over a container as if it were circular. The container must have the following members defined:...
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
bool operator!=(const ConstCirculator< ContainerType > &c) const
Check for inequality of this iterator with another iterator that.
Namespace for OpenFOAM.