Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Iterators.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #include <iosfwd>
34 #include <iterator>
35 #include <utility>
36 
37 namespace ogdf {
38 
40 template<typename IT>
41 class Range {
42  IT m_begin;
43  IT m_end;
44 
45 public:
46  Range() { }
47 
48  explicit Range(IT begin) : m_begin(begin) { }
49 
50  Range(IT begin, IT end) : m_begin(begin), m_end(end) { }
51 
52  IT begin() const { return m_begin; }
53 
54  IT end() const { return m_end; }
55 };
56 
58 template<typename IT1, typename IT2>
59 class ZipIterator {
60  IT1 m_iter1;
61  IT2 m_iter2;
62 
63 public:
64  // iterator traits
65  using iterator_category = std::input_iterator_tag;
66  using value_type = typename std::pair<typename IT1::value_type, typename IT2::value_type>;
67  using difference_type = std::ptrdiff_t;
68  using pointer = value_type*;
70 
71  explicit ZipIterator() { }
72 
73  explicit ZipIterator(const IT1& mIter1, const IT2& mIter2)
74  : m_iter1(mIter1), m_iter2(mIter2) { }
75 
76  bool operator==(const ZipIterator<IT1, IT2>& rhs) const {
77  return m_iter1 == rhs.m_iter1 && m_iter2 == rhs.m_iter2;
78  }
79 
80  bool operator!=(const ZipIterator<IT1, IT2>& rhs) const { return !(rhs == *this); }
81 
82  value_type operator*() { return std::make_pair(*m_iter1, *m_iter2); }
83 
84  bool checkOnlyOneEnded(const IT1& mEnd1, const IT2& mEnd2) {
85  bool e1 = m_iter1 == mEnd1;
86  bool e2 = m_iter2 == mEnd2;
87  return e1 ^ e2;
88  }
89 
92  ++m_iter1;
93  ++m_iter2;
94  return *this;
95  }
96 
100  ++m_iter1;
101  ++m_iter2;
102  return before;
103  }
104 };
105 
106 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::ZipIterator::iterator_category
std::input_iterator_tag iterator_category
Definition: Iterators.h:65
ogdf::ZipIterator::operator!=
bool operator!=(const ZipIterator< IT1, IT2 > &rhs) const
Definition: Iterators.h:80
ogdf::ZipIterator::pointer
value_type * pointer
Definition: Iterators.h:68
ogdf::Range::end
IT end() const
Definition: Iterators.h:54
ogdf::Range::Range
Range()
Definition: Iterators.h:46
ogdf::ZipIterator::operator++
ZipIterator< IT1, IT2 > operator++(int)
Increment operator (postfix, returns previous value).
Definition: Iterators.h:98
ogdf::ZipIterator::m_iter1
IT1 m_iter1
Definition: Iterators.h:60
ogdf::ZipIterator::ZipIterator
ZipIterator(const IT1 &mIter1, const IT2 &mIter2)
Definition: Iterators.h:73
ogdf::ZipIterator::difference_type
std::ptrdiff_t difference_type
Definition: Iterators.h:67
ogdf::Direction::before
@ before
ogdf::Range::m_begin
IT m_begin
Definition: Iterators.h:42
ogdf::Range::Range
Range(IT begin)
Definition: Iterators.h:48
ogdf::Range::Range
Range(IT begin, IT end)
Definition: Iterators.h:50
ogdf::ZipIterator::operator==
bool operator==(const ZipIterator< IT1, IT2 > &rhs) const
Definition: Iterators.h:76
ogdf::ZipIterator::ZipIterator
ZipIterator()
Definition: Iterators.h:71
ogdf::Range::m_end
IT m_end
Definition: Iterators.h:43
ogdf::Range
Simple before-C++20 version for std::ranges::ref_view.
Definition: Iterators.h:41
ogdf::ZipIterator::reference
value_type & reference
Definition: Iterators.h:69
ogdf::ZipIterator::operator*
value_type operator*()
Definition: Iterators.h:82
ogdf::Range::begin
IT begin() const
Definition: Iterators.h:52
ogdf::ZipIterator::value_type
typename std::pair< typename IT1::value_type, typename IT2::value_type > value_type
Definition: Iterators.h:66
ogdf::ZipIterator::m_iter2
IT2 m_iter2
Definition: Iterators.h:61
ogdf::ZipIterator::operator++
ZipIterator< IT1, IT2 > & operator++()
Increment operator (prefix, returns result).
Definition: Iterators.h:91
ogdf::ZipIterator
Simple before-C++20 version for std::ranges::zip_view.
Definition: Iterators.h:59
ogdf::ZipIterator::checkOnlyOneEnded
bool checkOnlyOneEnded(const IT1 &mEnd1, const IT2 &mEnd2)
Definition: Iterators.h:84