Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
graph_iterators.h
Go to the documentation of this file.
32#pragma once
33
34#include <ogdf/basic/basic.h>
35
36#include <iosfwd>
37#include <iterator>
38#include <type_traits>
39
40namespace ogdf {
41
42namespace internal {
43
44template<class GraphObjectPtr, bool isReverse, bool isConst>
46
47template<class GraphObjectPtr>
49template<class GraphObjectPtr>
51
52template<class GraphObjectPtr, bool isReverse, bool isConst>
54 friend class GraphIteratorBase<GraphObjectPtr, !isReverse, isConst>;
56
57 GraphObjectPtr m_ptr;
58
59public:
60 using difference_type = std::ptrdiff_t;
61 using value_type = typename std::conditional<isConst, const GraphObjectPtr, GraphObjectPtr>::type;
62 using iterator_category = std::bidirectional_iterator_tag;
65
66 GraphIteratorBase() : m_ptr(nullptr) { }
67
68 GraphIteratorBase(GraphObjectPtr ptr) : m_ptr(ptr) { }
69
70 template<bool isArgReverse>
73
74 bool operator==(const T& other) const { return m_ptr == other.m_ptr; }
75
76 bool operator!=(const T& other) const { return m_ptr != other.m_ptr; }
77
78 const GraphObjectPtr& operator*() const { return m_ptr; }
79
82 OGDF_ASSERT(m_ptr != nullptr);
83 m_ptr = isReverse ? m_ptr->pred() : m_ptr->succ();
84 return *this;
85 }
86
89 OGDF_ASSERT(m_ptr != nullptr);
90 GraphObjectPtr ptr = m_ptr;
91 m_ptr = isReverse ? m_ptr->pred() : m_ptr->succ();
92 return ptr;
93 }
94
97 OGDF_ASSERT(m_ptr != nullptr);
98 m_ptr = isReverse ? m_ptr->succ() : m_ptr->pred();
99 return *this;
100 }
101
104 OGDF_ASSERT(m_ptr != nullptr);
105 GraphObjectPtr ptr = m_ptr;
106 m_ptr = isReverse ? m_ptr->succ() : m_ptr->pred();
107 return ptr;
108 }
109};
110
111template<class ArrayType, bool isConst>
112class GraphArrayIteratorBase;
113
114template<class ArrayType>
116template<class ArrayType>
118
119template<class ArrayType, bool isConst>
121 friend class GraphArrayIteratorBase<ArrayType, true>;
122
123public:
125 using key_type = typename ArrayType::key_type;
127 using value_type = typename std::conditional<isConst, const typename ArrayType::value_type,
128 typename ArrayType::value_type>::type;
130 using array_pointer_type = typename std::conditional<isConst, const ArrayType*, ArrayType*>::type;
131
133 GraphArrayIteratorBase() : m_key(nullptr), m_array(nullptr) { }
134
137
139 template<bool isArgConst, typename std::enable_if<isConst || !isArgConst, int>::type = 0>
142
144 // gcc9 complains since it cannot match the templated constructor above (-Werror=deprecated-copy).
147
155
157 key_type key() const { return m_key; }
158
160 value_type& value() const { return (*m_array)[m_key]; }
161
163 value_type& operator*() const { return (*m_array)[m_key]; }
164
167 return m_key == iter.m_key && m_array == iter.m_array;
168 }
169
172 return !operator==(iter);
173 }
174
177 OGDF_ASSERT(m_key != nullptr);
178 m_key = ArrayType::findSuccKey(m_key);
179 return *this;
180 }
181
185 m_key = ArrayType::findSuccKey(m_key);
186 return iter;
187 }
188
191 OGDF_ASSERT(m_key != nullptr);
192 m_key = ArrayType::findPredKey(m_key);
193 return *this;
194 }
195
199 m_key = ArrayType::findPredKey(m_key);
200 return iter;
201 }
202
203private:
206};
207
208template<typename It>
212
213public:
214 SimpleRange(It&& begin, It&& end) : m_begin(std::move(begin)), m_end(std::move(end)) { }
215
216 SimpleRange(const It& begin, const It& end) : m_begin(begin), m_end(end) { }
217
218 SimpleRange() = default;
219
220 const It& begin() const { return m_begin; }
221
222 const It& end() const { return m_end; }
223
224 It& begin() { return m_begin; }
225
226 It& end() { return m_end; }
227};
228
229}
230}
Basic declarations, included by all source files.
GraphArrayIteratorBase(const GraphArrayIteratorBase< ArrayType, isConst > &iter)
Copy constructor.
GraphArrayIteratorBase< ArrayType, isConst > & operator=(const GraphArrayIteratorBase< ArrayType, isConst > &iter)
Copy assignment operator.
key_type key() const
Index in m_array.
array_pointer_type m_array
The array.
GraphArrayIteratorBase< ArrayType, isConst > & operator--()
Decrement operator (prefix).
GraphArrayIteratorBase(const GraphArrayIteratorBase< ArrayType, isArgConst > &iter)
Constructor.
value_type & value() const
Value of m_array at index m_key.
bool operator!=(const GraphArrayIteratorBase< ArrayType, isConst > &iter) const
Inequality operator.
typename ArrayType::key_type key_type
Index type of the associated array.
GraphArrayIteratorBase< ArrayType, isConst > operator--(int)
Decrement operator (postfix).
typename std::conditional< isConst, const ArrayType *, ArrayType * >::type array_pointer_type
Type of the array.
GraphArrayIteratorBase< ArrayType, isConst > operator++(int)
Increment operator (postfix).
value_type & operator*() const
Value of m_array at index m_key.
typename std::conditional< isConst, const typename ArrayType::value_type, typename ArrayType::value_type >::type value_type
Value type of the associated array.
GraphArrayIteratorBase< ArrayType, isConst > & operator++()
Increment operator (prefix).
GraphArrayIteratorBase(key_type key, array_pointer_type a)
Constructor.
bool operator==(const GraphArrayIteratorBase< ArrayType, isConst > &iter) const
Equality operator.
T operator++(int)
Increment operator (postfix).
const GraphObjectPtr & operator*() const
GraphIteratorBase(GraphObjectPtr ptr)
bool operator!=(const T &other) const
GraphIteratorBase< GraphObjectPtr, isReverse, isConst > T
std::bidirectional_iterator_tag iterator_category
typename std::conditional< isConst, const GraphObjectPtr, GraphObjectPtr >::type value_type
GraphIteratorBase(GraphIteratorBase< GraphObjectPtr, isArgReverse, isConst > &it)
T & operator--()
Decrement operator (prefix).
T & operator++()
Increment operator (prefix).
bool operator==(const T &other) const
SimpleRange(const It &begin, const It &end)
SimpleRange(It &&begin, It &&end)
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
Definition GML.h:111