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