Dune Core Modules (2.5.0)

corneriterator.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_IO_FILE_VTK_CORNERITERATOR_HH
5#define DUNE_GRID_IO_FILE_VTK_CORNERITERATOR_HH
6
7#include <iterator>
8
11
12#include <dune/geometry/referenceelements.hh>
13
14#include <dune/grid/io/file/vtk/corner.hh>
15
16namespace Dune
17{
20
21 namespace VTK {
22
24
28 template<typename CellIterator>
31 < CornerIterator<CellIterator>,
32 const Corner<typename std::remove_const<typename std::iterator_traits<
33 CellIterator>::value_type>::type>,
34 const Corner<typename std::remove_const<typename std::iterator_traits<
35 CellIterator>::value_type>::type>&,
36 typename std::iterator_traits<CellIterator>::difference_type>
37 {
38 public:
39 // reiterate the facades typedefs here
41 typedef VTK::Corner<typename std::remove_const<typename std::iterator_traits<
42 CellIterator>::value_type>::type> Corner;
43 typedef const Corner Value;
44 typedef Value& Reference;
45 typedef typename std::iterator_traits<CellIterator>::difference_type
46 DifferenceType;
47
48 typedef typename std::iterator_traits<CellIterator>::value_type::Geometry::ctype
49 ctype;
50 static const unsigned dim = std::iterator_traits<CellIterator>::
51 value_type::mydimension;
53
54 private:
56 DifferenceType> Facade;
57
58 CellIterator cellit;
59 CellIterator cellend;
60 Corner corner;
61
62 public:
63 Reference dereference() const {
64 return corner;
65 }
66
67 bool isDereferencable() const {
68 return cellit != cellend;
69 }
70
71 bool equals(const DerivedType& other) const {
72 bool mePassedTheEnd = !isDereferencable();
73 bool otherPassedTheEnd = !other.isDereferencable();
74 // both are passed the end => return true
75 if(mePassedTheEnd && otherPassedTheEnd) return true;
76 // one is passed the end => return false
77 if(mePassedTheEnd || otherPassedTheEnd) return false;
78 // none is passed the end, do their iterators and indices match?
79 return cellit == other.cellit &&
80 corner.duneIndex() == other.corner.duneIndex();
81 }
82
83 void increment() {
84 int index = corner.vtkIndex();
85 ++index;
86 if(index == Refelems::general(cellit->type()).size(dim)) {
87 ++cellit;
88 if(cellit != cellend) {
89 corner.cell(*cellit);
90 corner.vtkIndex(0);
91 }
92 }
93 else
94 corner.vtkIndex(index);
95 }
96
98
103 CornerIterator(const CellIterator& cellit_, const CellIterator& cellend_,
104 unsigned vtkIndex = 0)
105 : cellit(cellit_), cellend(cellend_)
106 {
107 if(cellit != cellend) {
108 corner.cell(*cellit);
109 corner.vtkIndex(vtkIndex);
110 }
111 }
113
116 CornerIterator(const CellIterator& cellend_)
117 : cellit(cellend_), cellend(cellend_)
118 { }
119 };
120
121 } // namespace VTK
122
124
125} // namespace Dune
126
127#endif // DUNE_GRID_IO_FILE_VTK_CORNERITERATOR_HH
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:144
iterate over the corners of some cell range
Definition: corneriterator.hh:37
CornerIterator(const CellIterator &cellit_, const CellIterator &cellend_, unsigned vtkIndex=0)
construct a CornerIterator
Definition: corneriterator.hh:103
CornerIterator(const CellIterator &cellend_)
construct a CornerIterator
Definition: corneriterator.hh:116
simple class representing a corner of a cell
Definition: corner.hh:23
unsigned vtkIndex() const
get the index of the corner within the cell in VTK-numbering
Definition: corner.hh:61
unsigned duneIndex() const
get the index of the corner within the cell in Dune-numbering
Definition: corner.hh:53
const Cell & cell() const
get reference to the cell
Definition: corner.hh:44
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:11
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:752
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:757
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)