Dune Core Modules (unstable)

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