Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Iterators.h
Go to the documentation of this file.
1
31#pragma once
32
33#include <functional>
34#include <utility>
35
36namespace ogdf {
37namespace internal {
38namespace gcm {
39
40namespace datastructure {
41template<typename Iterator>
43protected:
44 Iterator m_begin;
45 Iterator m_cur;
46 Iterator m_end;
47 const std::function<bool(const typename Iterator::T)> m_predicate;
48
49public:
50 using T = typename Iterator::T;
51
52 FilterIterator(Iterator begin, Iterator end,
53 const std::function<bool(const typename Iterator::T)>& _predicate)
54 : m_begin(std::move(begin))
55 , m_cur(m_begin)
56 , m_end(std::move(end))
57 , m_predicate(std::move(_predicate)) {
58 if (m_cur != m_end && !m_predicate(*m_cur)) {
59 ++(*this);
60 }
61 // nothing to do
62 }
63
65 do {
66 --m_cur;
67 } while (m_cur != m_begin && !m_predicate(*m_cur));
68 return *this;
69 }
70
72 do {
73 ++m_cur;
74 } while (m_cur != m_end && !m_predicate(*m_cur));
75 return *this;
76 }
77
78 bool operator==(const FilterIterator<Iterator>& b) const { return m_cur == b.m_cur; }
79
80 bool operator!=(const FilterIterator<Iterator>& b) const { return m_cur != b.m_cur; }
81
83 if (m_cur != m_end && !m_predicate(*m_cur)) {
84 ++(*this);
85 }
86 return *m_cur;
87 }
88};
89
90template<typename Iterator>
92private:
93 Iterator m_begin;
94 Iterator m_end;
95
96public:
97 IteratorRange(Iterator begin, Iterator end) : m_begin(begin), m_end(end) { }
98
99 Iterator begin() { return m_begin; }
100
101 Iterator end() { return m_end; }
102};
103
104
105}
106
107}
108}
109}
FilterIterator< Iterator > & operator--()
Definition Iterators.h:64
bool operator==(const FilterIterator< Iterator > &b) const
Definition Iterators.h:78
FilterIterator< Iterator > & operator++()
Definition Iterators.h:71
FilterIterator(Iterator begin, Iterator end, const std::function< bool(const typename Iterator::T)> &_predicate)
Definition Iterators.h:52
bool operator!=(const FilterIterator< Iterator > &b) const
Definition Iterators.h:80
const std::function< bool(const typename Iterator::T)> m_predicate
Definition Iterators.h:47
IteratorRange(Iterator begin, Iterator end)
Definition Iterators.h:97
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Definition GML.h:110