preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RangeAccessor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/iterator/iterator_facade.hpp>
4
5namespace precice::mesh {
13template <typename Source, typename Value>
14class IndexRangeIterator : public boost::iterator_facade<
15 IndexRangeIterator<Source, const Value>,
16 const Value,
17 boost::random_access_traversal_tag> {
18public:
19 IndexRangeIterator() = default;
20 IndexRangeIterator(Source *src, size_t index)
21 : src_(src), idx_(index) {}
22
23 const Value &dereference() const
24 {
25 using Coord = decltype(src_->vertex(idx_).rawCoords());
26 static_assert(
28 "Coordinate type must be a reference!");
29 static_assert(
31 "Exposed and accessed types must match!");
32 return static_cast<const Value &>(src_->vertex(idx_).rawCoords());
33 }
34
35 size_t equal(const IndexRangeIterator<Source, Value> &other) const
36 {
37 return other.idx_ == idx_ && other.src_ == src_;
38 }
39
40 void increment()
41 {
42 ++idx_;
43 }
44
45 void decrement()
46 {
47 --idx_;
48 }
49
50 void advance(size_t n)
51 {
52 idx_ += n;
53 }
54
56 {
57 return other.idx_ - idx_;
58 }
59
60private:
61 Source *src_{nullptr};
62 size_t idx_{0};
63};
64
65} // namespace precice::mesh
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
provides Mesh, Data and primitives.