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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2015 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Circulator
28 
29 Description
30  Walks over a container as if it were circular. The container must have the
31  following members defined:
32  - value_type
33  - size_type
34  - difference_type
35  - iterator
36  - reference
37 
38  Examples
39 
40  \code
41  face f(identity(5));
42 
43  // Construct Circulator from the face
44  Circulator<face> circ(f);
45 
46  // First check that the Circulator has a size to iterate over.
47  // Then circulate around the list starting and finishing at the fulcrum.
48  if (circ.size()) do
49  {
50  circ() += 1;
51 
52  Info<< "Iterate forwards over face : " << circ() << endl;
53 
54  } while (circ.circulate(CirculatorBase::CLOCKWISE));
55  \endcode
56 
57 SourceFiles
58  CirculatorI.H
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef Circulator_H
63 #define Circulator_H
64 
65 #include "CirculatorBase.H"
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class Circulator Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<class ContainerType>
78 class Circulator
79 :
80  public CirculatorBase
81 {
82 
83 protected:
84 
85  // Protected data
86 
87  //- Iterator pointing to the beginning of the container
88  typename ContainerType::iterator begin_;
89 
90  //- Iterator pointing to the end of the container
91  typename ContainerType::iterator end_;
92 
93  //- Random access iterator for traversing ContainerType.
94  typename ContainerType::iterator iter_;
95 
96  //- Iterator holding the location of the fulcrum (start and end) of
97  // the container. Used to decide when the iterator should stop
98  // circulating over the container
99  typename ContainerType::iterator fulcrum_;
100 
101 
102 public:
103 
104  // STL type definitions
105 
106  //- Type of values ContainerType contains.
107  typedef typename ContainerType::value_type value_type;
108 
109  //- The type that can represent the size of ContainerType
110  typedef typename ContainerType::size_type size_type;
111 
112  //- The type that can represent the difference between any two
113  // iterator objects.
114  typedef typename ContainerType::difference_type difference_type;
115 
116  //- Random access iterator for traversing ContainerType.
117  typedef typename ContainerType::iterator iterator;
118 
119  //- Type that can be used for storing into
120  // ContainerType::value_type objects.
121  typedef typename ContainerType::reference reference;
122 
123 
124  // Constructors
125 
126  //- Construct null
127  inline Circulator();
128 
129  //- Construct from a container.
130  inline explicit Circulator(ContainerType& container);
131 
132  //- Construct from two iterators
133  inline Circulator(const iterator& begin, const iterator& end);
134 
135  //- Construct as copy
136  inline Circulator(const Circulator<ContainerType>&);
137 
138 
139  //- Destructor
140  ~Circulator();
141 
142 
143  // Member Functions
144 
145  //- Return the range of the iterator
146  inline size_type size() const;
147 
148  //- Circulate around the list in the given direction
149  inline bool circulate(const CirculatorBase::direction dir = NONE);
150 
151  //- Set the fulcrum to the current position of the iterator
152  inline void setFulcrumToIterator();
153 
154  //- Set the iterator to the current position of the fulcrum
155  inline void setIteratorToFulcrum();
156 
157  //- Return the distance between the iterator and the fulcrum. This is
158  // equivalent to the number of rotations of the Circulator.
159  inline difference_type nRotations() const;
160 
161  //- Dereference the next iterator and return
162  inline reference next() const;
163 
164  //- Dereference the previous iterator and return
165  inline reference prev() const;
166 
167 
168  // Member Operators
169 
170  //- Assignment operator for Circulators that operate on the same
171  // container type
172  inline void operator=(const Circulator<ContainerType>&);
173 
174  //- Prefix increment. Increments the iterator.
175  // Sets the iterator to the beginning of the container if it reaches
176  // the end
178 
179  //- Postfix increment. Increments the iterator.
180  // Sets the iterator to the beginning of the container if it reaches
181  // the end
183 
184  //- Prefix decrement. Decrements the iterator.
185  // Sets the iterator to the end of the container if it reaches
186  // the beginning
188 
189  //- Postfix decrement. Decrements the iterator.
190  // Sets the iterator to the end of the container if it reaches
191  // the beginning
193 
194  //- Check for equality of this iterator with another iterator that
195  // operate on the same container type
196  inline bool operator==(const Circulator<ContainerType>& c) const;
197 
198  //- Check for inequality of this iterator with another iterator that
199  // operate on the same container type
200  inline bool operator!=(const Circulator<ContainerType>& c) const;
201 
202  //- Dereference the iterator and return
203  inline reference operator*() const;
204 
205  //- Dereference the iterator and return
206  inline reference operator()() const;
207 
208  //- Return the difference between this iterator and another iterator
209  // that operate on the same container type
210  inline difference_type operator-
211  (
213  ) const;
214 };
215 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 } // End namespace Foam
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 #include "CirculatorI.H"
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
Foam::Circulator::operator==
bool operator==(const Circulator< ContainerType > &c) const
Check for equality of this iterator with another iterator that.
Definition: CirculatorI.H:236
Foam::Circulator::operator*
reference operator*() const
Dereference the iterator and return.
Definition: CirculatorI.H:262
Foam::Circulator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: CirculatorI.H:101
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
Foam::Circulator::size_type
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
Definition: Circulator.H:109
Foam::Circulator::fulcrum_
ContainerType::iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
Definition: Circulator.H:98
Foam::Circulator::setFulcrumToIterator
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: CirculatorI.H:119
Foam::Circulator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: Circulator.H:77
Foam::Circulator::operator++
Circulator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
Definition: CirculatorI.H:188
Foam::Circulator::operator!=
bool operator!=(const Circulator< ContainerType > &c) const
Check for inequality of this iterator with another iterator that.
Definition: CirculatorI.H:252
Foam::Circulator::difference_type
ContainerType::difference_type difference_type
The type that can represent the difference between any two.
Definition: Circulator.H:113
Foam::Circulator::iterator
ContainerType::iterator iterator
Random access iterator for traversing ContainerType.
Definition: Circulator.H:116
Foam::Circulator::prev
reference prev() const
Dereference the previous iterator and return.
Definition: CirculatorI.H:155
Foam::Circulator::operator=
void operator=(const Circulator< ContainerType > &)
Assignment operator for Circulators that operate on the same.
Definition: CirculatorI.H:170
Foam::Circulator::operator()
reference operator()() const
Dereference the iterator and return.
Definition: CirculatorI.H:270
Foam::Circulator::Circulator
Circulator()
Construct null.
Definition: CirculatorI.H:32
Foam::Circulator::reference
ContainerType::reference reference
Type that can be used for storing into.
Definition: Circulator.H:120
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:76
Foam::Circulator::iter_
ContainerType::iterator iter_
Random access iterator for traversing ContainerType.
Definition: Circulator.H:93
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Circulator::next
reference next() const
Dereference the next iterator and return.
Definition: CirculatorI.H:142
Foam::CirculatorBase::direction
direction
Direction type enumeration.
Definition: CirculatorBase.H:53
Foam::Circulator::~Circulator
~Circulator()
Destructor.
Definition: CirculatorI.H:85
CirculatorI.H
Foam::Circulator::nRotations
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Definition: CirculatorI.H:134
CirculatorBase.H
Foam::Circulator::value_type
ContainerType::value_type value_type
Type of values ContainerType contains.
Definition: Circulator.H:106
Foam::Circulator::size
size_type size() const
Return the range of the iterator.
Definition: CirculatorI.H:93
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Circulator::end_
ContainerType::iterator end_
Iterator pointing to the end of the container.
Definition: Circulator.H:90
Foam::CirculatorBase::NONE
Definition: CirculatorBase.H:55
Foam::CirculatorBase
Base class for circulators.
Definition: CirculatorBase.H:46
Foam::Circulator::begin_
ContainerType::iterator begin_
Iterator pointing to the beginning of the container.
Definition: Circulator.H:87
Foam::Circulator::setIteratorToFulcrum
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
Definition: CirculatorI.H:126
Foam::Circulator::operator--
Circulator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
Definition: CirculatorI.H:212