preCICE v3.1.2
Loading...
Searching...
No Matches
RangeAccessor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/iterator/iterator_facade.hpp>
4
5namespace precice {
6namespace mesh {
14template <typename Source, typename Value>
15class IndexRangeIterator : public boost::iterator_facade<
16 IndexRangeIterator<Source, const Value>,
17 const Value,
18 boost::random_access_traversal_tag> {
19public:
20 IndexRangeIterator() = default;
21 IndexRangeIterator(Source *src, size_t index)
22 : src_(src), idx_(index) {}
23
24 const Value &dereference() const
25 {
26 using Coord = decltype(src_->vertex(idx_).rawCoords());
27 static_assert(
29 "Coordinate type must be a reference!");
30 static_assert(
32 "Exposed and accessed types must match!");
33 return static_cast<const Value &>(src_->vertex(idx_).rawCoords());
34 }
35
36 size_t equal(const IndexRangeIterator<Source, Value> &other) const
37 {
38 return other.idx_ == idx_ && other.src_ == src_;
39 }
40
41 void increment()
42 {
43 ++idx_;
44 }
45
46 void decrement()
47 {
48 --idx_;
49 }
50
51 void advance(size_t n)
52 {
53 idx_ += n;
54 }
55
57 {
58 return other.idx_ - idx_;
59 }
60
61private:
62 Source *src_{nullptr};
63 size_t idx_{0};
64};
65
66} // namespace mesh
67} // namespace precice
unsigned int index
size_t distance_to(const IndexRangeIterator< Source, Value > &other) const
size_t equal(const IndexRangeIterator< Source, Value > &other) const
size_t idx_
the current index to access
const Value & dereference() const
IndexRangeIterator(Source *src, size_t index)
Source * src_
the source to access
Main namespace of the precice library.