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