BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
concrete_subentity_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_subentity_iterator_hpp
22 #define bempp_concrete_subentity_iterator_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "entity_iterator.hpp"
27 #include "concrete_entity_decl.hpp"
28 
29 #include <dune/common/static_assert.hh>
30 
31 namespace Bempp
32 {
33 
37 template<typename DuneEntity, int codimSub>
39 {
40  dune_static_assert(DuneEntity::codimension == 0,
41  "ConcreteSubentityIterator: only codim-0 entities "
42  "support iteration over subentities");
43  dune_static_assert((int)DuneEntity::codimension < (int)ConcreteSubentityIterator::codimension,
44  "ConcreteSubentityIterator: subentity codimension "
45  "must exceed entity codimension");
46 public:
48  typedef typename DuneEntity::template Codim<codimSub>::EntityPointer DuneSubentityPointer;
50  typedef typename DuneSubentityPointer::Entity DuneSubentity;
51 
52 private:
53  const DuneEntity* m_dune_entity;
54  DuneSubentityPointer m_dune_subentity_ptr;
56  m_subentity;
57  const DomainIndex& m_domain_index;
58  int m_cur_n;
59 
60  void updateFinished() {
61  this->m_finished =
62  (m_cur_n == m_dune_entity->template count<codimSub>());
63  }
64 
65  void updateSubentity() {
66  if (!this->finished()) {
67  m_dune_subentity_ptr = m_dune_entity->template subEntity<codimSub>(
68  m_cur_n);
69  m_subentity.setDuneEntity(&*m_dune_subentity_ptr);
70  }
71  }
72 
73 public:
77  explicit ConcreteSubentityIterator(const DuneEntity* dune_entity,
78  const DomainIndex& domain_index) :
79  m_dune_entity(dune_entity), m_dune_subentity_ptr(
80  m_dune_entity->template subEntity<codimSub>(0)),
81  m_subentity(&*m_dune_subentity_ptr, domain_index),
82  m_domain_index(domain_index), m_cur_n(0) {
83  updateFinished();
84  }
85 
86  virtual void next() {
87  ++m_cur_n;
88  updateFinished();
89  updateSubentity();
90  }
91 
93  return m_subentity;
94  }
95 
96  virtual std::auto_ptr<EntityPointer<ConcreteSubentityIterator::codimension> >
97  frozen() const {
98  const int codim = ConcreteSubentityIterator::codimension;
99  return std::auto_ptr<EntityPointer<codim> >(
101  m_subentity.duneEntity(), m_domain_index));
102  }
103 };
104 
105 } // namespace Bempp
106 
107 #endif
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
Wrapper of a Dune entity of type DuneEntity and codimension codim.
Definition: concrete_entity_decl.hpp:46
virtual void next()
Increment iterator.
Definition: concrete_subentity_iterator.hpp:86
virtual std::auto_ptr< EntityPointer< ConcreteSubentityIterator::codimension > > frozen() const
A stable pointer to the entity currently referenced by the iterator.
Definition: concrete_subentity_iterator.hpp:97
ConcreteSubentityIterator(const DuneEntity *dune_entity, const DomainIndex &domain_index)
Constructor.
Definition: concrete_subentity_iterator.hpp:77
DuneEntity::template Codim< codimSub >::EntityPointer DuneSubentityPointer
Type of the Dune entity pointer corresponding to DuneEntity.
Definition: concrete_subentity_iterator.hpp:48
Definition: domain_index.hpp:32
Iterator over the subentities of codimension codimSub of a given Dune entity of type DuneEntity...
Definition: concrete_subentity_iterator.hpp:38
DuneSubentityPointer::Entity DuneSubentity
Type of the appropriate subentity of DuneEntity.
Definition: concrete_subentity_iterator.hpp:50
virtual const Entity< ConcreteSubentityIterator::codimension > & entity() const
Read-only access to the entity referenced by the iterator.
Definition: concrete_subentity_iterator.hpp:92
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