BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
concrete_range_entity_iterator.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef bempp_concrete_range_entity_iterator_hpp
22 #define bempp_concrete_range_entity_iterator_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "entity_iterator.hpp"
27 #include "concrete_entity_decl.hpp"
28 
29 namespace Bempp
30 {
31 
32 class DomainIndex;
33 
42 template<typename DuneEntityIt, typename DuneEntityPointer>
44  DuneEntityIt::codimension>
45 {
46 private:
47  DuneEntityIt m_begin, m_end, m_cur;
48  ConcreteEntity<ConcreteRangeEntityIterator::codimension,
49  typename DuneEntityIt::Entity> m_entity;
50  const DomainIndex& m_domain_index;
51 
52  void updateEntity() {
53  if (!this->finished())
54  m_entity.setDuneEntity(&*m_cur);
55  }
56 
57  void updateFinished() {
58  this->m_finished = (m_cur == m_end);
59  }
60 
61 public:
63  ConcreteRangeEntityIterator(const DuneEntityIt& begin,
64  const DuneEntityIt& end,
65  const DomainIndex& domain_index) :
66  m_begin(begin), m_end(end), m_cur(begin), m_entity(domain_index),
67  m_domain_index(domain_index) {
68  updateFinished();
69  updateEntity();
70  }
71 
72  virtual void next() {
73  ++m_cur;
74  updateFinished();
75  updateEntity();
76  }
77 
79  return m_entity;
80  }
81 
82  virtual std::auto_ptr<EntityPointer<ConcreteRangeEntityIterator::codimension> > frozen() const {
83  const int codim = ConcreteRangeEntityIterator::codimension;
84  return std::auto_ptr<EntityPointer<codim> >(
86  *m_cur, m_domain_index));
87  }
88 };
89 
90 } // namespace Bempp
91 
92 #endif
ConcreteRangeEntityIterator(const DuneEntityIt &begin, const DuneEntityIt &end, const DomainIndex &domain_index)
Constructor. The iterator will go over the range [begin, end).
Definition: concrete_range_entity_iterator.hpp:63
virtual std::auto_ptr< EntityPointer< ConcreteRangeEntityIterator::codimension > > frozen() const
A stable pointer to the entity currently referenced by the iterator.
Definition: concrete_range_entity_iterator.hpp:82
Wrapper of a Dune entity pointer of type DuneEntityPointer.
Definition: concrete_entity_pointer.hpp:37
Abstract wrapper of an entity of codimension codim.
Definition: entity.hpp:46
Iterator over entities referenced by a range of Dune iterators of type DuneEntityIt.
Definition: concrete_range_entity_iterator.hpp:43
Wrapper of a Dune entity of type DuneEntity and codimension codim.
Definition: concrete_entity_decl.hpp:46
virtual void next()
Increment iterator.
Definition: concrete_range_entity_iterator.hpp:72
Definition: domain_index.hpp:32
virtual const Entity< ConcreteRangeEntityIterator::codimension > & entity() const
Read-only access to the entity referenced by the iterator.
Definition: concrete_range_entity_iterator.hpp:78
bool finished() const
True if iterator points past the end of the iteration range.
Definition: entity_iterator.hpp:68
Abstract base class for iterators over entities.
Definition: entity_iterator.hpp:59