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_
Definition: ConstCirculator.H:99
Foam::ConstCirculator::end_
ContainerType::const_iterator end_
Definition: ConstCirculator.H:102
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Definition: stdFoam.H:96
Foam::ConstCirculator::const_reference
ContainerType::const_reference const_reference
Definition: ConstCirculator.H:132
Foam::ConstCirculator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: ConstCirculator.H:89
Foam::ConstCirculator::size_type
ContainerType::size_type size_type
Definition: ConstCirculator.H:121
Foam::ConstCirculator::operator!=
bool operator!=(const ConstCirculator< ContainerType > &c) const
Definition: ConstCirculatorI.H:250
Foam::ConstCirculator::operator=
void operator=(const ConstCirculator< ContainerType > &)
Definition: ConstCirculatorI.H:168
Foam::ConstCirculator::setIteratorToFulcrum
void setIteratorToFulcrum()
Definition: ConstCirculatorI.H:124
Foam::ConstCirculator::difference_type
ContainerType::difference_type difference_type
Definition: ConstCirculator.H:125
Foam::ConstCirculator::~ConstCirculator
~ConstCirculator()
Definition: ConstCirculatorI.H:83
Foam::ConstCirculator::operator++
ConstCirculator< ContainerType > & operator++()
Definition: ConstCirculatorI.H:186
Foam::ConstCirculator::operator==
bool operator==(const ConstCirculator< ContainerType > &c) const
Definition: ConstCirculatorI.H:234
Foam::ConstCirculator::const_iterator
ContainerType::const_iterator const_iterator
Definition: ConstCirculator.H:128
Foam::ConstCirculator::fulcrum_
ContainerType::const_iterator fulcrum_
Definition: ConstCirculator.H:110
Foam::ConstCirculator::ConstCirculator
ConstCirculator()
Definition: ConstCirculatorI.H:27
Foam::ConstCirculator::size
size_type size() const
Definition: ConstCirculatorI.H:91
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:69
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Definition: stdFoam.H:129
Foam
Definition: atmBoundaryLayer.C:26
Foam::ConstCirculator::nRotations
difference_type nRotations() const
Definition: ConstCirculatorI.H:132
Foam::ConstCirculator::operator()
const_reference operator()() const
Definition: ConstCirculatorI.H:268
Foam::ConstCirculator::value_type
ContainerType::value_type value_type
Definition: ConstCirculator.H:118
Foam::CirculatorBase::direction
direction
Definition: CirculatorBase.H:47
Foam::ConstCirculator::operator*
const_reference operator*() const
Definition: ConstCirculatorI.H:260
Foam::ConstCirculator::iter_
ContainerType::const_iterator iter_
Definition: ConstCirculator.H:105
CirculatorBase.H
Foam::constant::universal::c
const dimensionedScalar c
Foam::CirculatorBase::NONE
@ NONE
Definition: CirculatorBase.H:49
Foam::ConstCirculator::setFulcrumToIterator
void setFulcrumToIterator()
Definition: ConstCirculatorI.H:117
Foam::ConstCirculator::next
const_reference next() const
Definition: ConstCirculatorI.H:140
Foam::CirculatorBase
Base class for circulators.
Definition: CirculatorBase.H:40
Foam::ConstCirculator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Definition: ConstCirculatorI.H:99
ConstCirculatorI.H
Foam::ConstCirculator::prev
const_reference prev() const
Definition: ConstCirculatorI.H:153
Foam::ConstCirculator::operator--
ConstCirculator< ContainerType > & operator--()
Definition: ConstCirculatorI.H:210