Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
associated_elements_iterator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3 * Author: Sebastian Reiter
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG_associated_elements_iterator
34#define __H__UG_associated_elements_iterator
35
36#include <iterator>
37#include <limits>
39
40namespace ug{
41
43
49template <class TElem, class TAssocElem, bool VSorted = false>
50class AssocElemIter : public std::iterator<std::input_iterator_tag, TAssocElem*>
51{
52 public:
54 ConsiderAll()) :
55 m_i(0),
56 m_cbConsiderElem(cbConsiderElem)
57 {}
58
59 AssocElemIter(Grid& grid, TElem* elem,
60 typename Grid::traits<TAssocElem>::callback cbConsiderElem =
61 ConsiderAll()) :
62 m_i(0),
63 m_cbConsiderElem(cbConsiderElem)
64 {
65 init(grid, elem);
66 }
67
69 {
70 m_cbConsiderElem(cbConsiderElem);
71 }
72
73 void reinit(Grid& grid, TElem* elem)
74 {
75 m_i = 0;
76 init(grid, elem);
77 }
78
79 void reinit(Grid& grid, TElem* elem,
81 {
82 m_i = 0;
84 init(grid, elem);
85 }
86
88 {
90 e.m_i = std::numeric_limits<size_t>::max();
91 return e;
92 }
93
94 bool valid() const {return m_i < m_assElems.size();}
95 bool invalid() const {return m_i >= m_assElems.size();}
96
97
98 AssocElemIter& operator ++() {increment(); return *this;}
99 AssocElemIter operator ++(int unused) {AssocElemIter i = *this; increment(); return i;}
100
102 bool operator ==(const AssocElemIter& iter) const {return equal(iter);}
104 bool operator !=(const AssocElemIter& iter) const {return !equal(iter);}
105
106 TAssocElem* operator *() {return dereference();}
107
108 private:
109 inline void init(Grid& grid, TElem* elem){
110 if(VSorted)
112 else
114
115 if(valid() && (!m_cbConsiderElem(dereference())))
116 increment();
117 }
118
120 inline bool equal(AssocElemIter const& other) const{
121 if(valid()){
122 if(other.valid()){
123 if(dereference() == *other)
124 return true;
125 }
126 }
127 else{
128 if(!other.valid())
129 return true;
130 }
131 return false;
132 }
133
135 void increment(){
136 while(1){
137 ++m_i;
138 if(valid()){
140 break;
141 }
142 else
143 break;
144 }
145 }
146
148 inline TAssocElem* dereference() const{
149 return m_assElems[m_i];
150 }
151
152 private:
153 size_t m_i;
156 };
157
158}// end of namespace
159
160#endif //__H__UG_associated_elements_iterator
Iterator that allows to traverse associated elements of a given element.
Definition associated_elements_iterator.h:51
bool operator==(const AssocElemIter &iter) const
returns true if both iterators are invalid or if both point to the same elemnt.
Definition associated_elements_iterator.h:102
AssocElemIter(Grid &grid, TElem *elem, typename Grid::traits< TAssocElem >::callback cbConsiderElem=ConsiderAll())
Definition associated_elements_iterator.h:59
bool operator!=(const AssocElemIter &iter) const
returns true if exactly one iterator is invalid or if the iterators point to different elements.
Definition associated_elements_iterator.h:104
TAssocElem * dereference() const
dereference
Definition associated_elements_iterator.h:148
AssocElemIter end() const
Definition associated_elements_iterator.h:87
void increment()
returns next iterator
Definition associated_elements_iterator.h:135
void set_callback(typename Grid::traits< TAssocElem >::callback cbConsiderElem)
Definition associated_elements_iterator.h:68
void init(Grid &grid, TElem *elem)
Definition associated_elements_iterator.h:109
Grid::traits< TAssocElem >::callback m_cbConsiderElem
Definition associated_elements_iterator.h:155
AssocElemIter & operator++()
Definition associated_elements_iterator.h:98
bool invalid() const
Definition associated_elements_iterator.h:95
TAssocElem * operator*()
Definition associated_elements_iterator.h:106
bool valid() const
Definition associated_elements_iterator.h:94
void reinit(Grid &grid, TElem *elem)
Definition associated_elements_iterator.h:73
void reinit(Grid &grid, TElem *elem, typename Grid::traits< TAssocElem >::callback cb)
Definition associated_elements_iterator.h:79
size_t m_i
Definition associated_elements_iterator.h:153
Grid::traits< TAssocElem >::secure_container m_assElems
Definition associated_elements_iterator.h:154
bool equal(AssocElemIter const &other) const
returns true if both iterators are invalid or if both point to the same elemnt.
Definition associated_elements_iterator.h:120
AssocElemIter(typename Grid::traits< TAssocElem >::callback cbConsiderElem=ConsiderAll())
Definition associated_elements_iterator.h:53
callback that always returns true
Definition basic_callbacks.h:50
Manages the elements of a grid and their interconnection.
Definition grid.h:132
void associated_elements(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' or which contain 'e' into elemsOut.
Definition grid_impl.hpp:466
void associated_elements_sorted(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' into elemsOut in the reference elements ord...
Definition grid_impl.hpp:503
virtual void init()
the ug namespace
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition grid.h:150
PointerConstArray< TElem * > secure_container
Definition grid.h:146