Circulator.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) 2012-2015 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::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  //- Construct as copy
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(const CirculatorBase::direction dir = NONE);
148 
149  //- Set the fulcrum to the current position of the iterator
150  inline void setFulcrumToIterator();
151 
152  //- Set the iterator to the current position of the fulcrum
153  inline void setIteratorToFulcrum();
154 
155  //- Return the distance between the iterator and the fulcrum. This is
156  // equivalent to the number of rotations of the Circulator.
157  inline difference_type nRotations() const;
158 
159  //- Dereference the next iterator and return
160  inline reference next() const;
161 
162  //- Dereference the previous iterator and return
163  inline reference prev() const;
164 
165 
166  // Member Operators
167 
168  //- Assignment operator for Circulators that operate on the same
169  // container type
170  inline void operator=(const Circulator<ContainerType>&);
171 
172  //- Prefix increment. Increments the iterator.
173  // Sets the iterator to the beginning of the container if it reaches
174  // the end
176 
177  //- Postfix increment. Increments the iterator.
178  // Sets the iterator to the beginning of the container if it reaches
179  // the end
181 
182  //- Prefix decrement. Decrements the iterator.
183  // Sets the iterator to the end of the container if it reaches
184  // the beginning
186 
187  //- Postfix decrement. Decrements the iterator.
188  // Sets the iterator to the end of the container if it reaches
189  // the beginning
191 
192  //- Check for equality of this iterator with another iterator that
193  // operate on the same container type
194  inline bool operator==(const Circulator<ContainerType>& c) const;
195 
196  //- Check for inequality 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  //- Dereference the iterator and return
201  inline reference operator*() const;
202 
203  //- Dereference the iterator and return
204  inline reference operator()() const;
205 
206  //- Return the difference between this iterator and another iterator
207  // that operate on the same container type
208  inline difference_type operator-
209  (
211  ) const;
212 };
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #include "CirculatorI.H"
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 #endif
226 
227 // ************************************************************************* //
reference operator*() const
Dereference the iterator and return.
Definition: CirculatorI.H:262
Circulator()
Construct null.
Definition: CirculatorI.H:29
size_type size() const
Return the range of the iterator.
Definition: CirculatorI.H:90
reference operator()() const
Dereference the iterator and return.
Definition: CirculatorI.H:270
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
bool operator==(const Circulator< ContainerType > &c) const
Check for equality of this iterator with another iterator that.
Definition: CirculatorI.H:236
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
reference prev() const
Dereference the previous iterator and return.
Definition: CirculatorI.H:152
ContainerType::iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
Definition: Circulator.H:96
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: CirculatorI.H:98
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
Walks over a container as if it were circular. The container must have the following members defined:...
Definition: Circulator.H:75
ContainerType::iterator iter_
Random access iterator for traversing ContainerType.
Definition: Circulator.H:91
Base class for circulators.
ContainerType::reference reference
Type that can be used for storing into.
Definition: Circulator.H:118
bool operator!=(const Circulator< ContainerType > &c) const
Check for inequality of this iterator with another iterator that.
Definition: CirculatorI.H:252
reference next() const
Dereference the next iterator and return.
Definition: CirculatorI.H:139
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.