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