Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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