Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

graph_iterators.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <functional>
35 
36 namespace ogdf {
37 
38 namespace internal {
39 
40 template<class GraphObjectPtr>
42  GraphObjectPtr m_ptr;
43 
44 public:
45  GraphIterator() : m_ptr(nullptr) { }
46  GraphIterator(GraphObjectPtr ptr) : m_ptr(ptr) { }
47 
48  bool operator==(const GraphIterator<GraphObjectPtr> &other) const {
49  return m_ptr == other.m_ptr;
50  }
51 
52  bool operator!=(const GraphIterator<GraphObjectPtr> &other) const {
53  return m_ptr != other.m_ptr;
54  }
55 
56  GraphObjectPtr operator*() {
57  return m_ptr;
58  }
59 
62  OGDF_ASSERT(m_ptr != nullptr);
63  m_ptr = m_ptr->succ();
64  return *this;
65  }
66 
69  OGDF_ASSERT(m_ptr != nullptr);
70  GraphObjectPtr ptr = m_ptr;
71  m_ptr = m_ptr->succ();
72  return ptr;
73  }
74 
77  OGDF_ASSERT(m_ptr != nullptr);
78  m_ptr = m_ptr->pred();
79  return *this;
80  }
81 
84  OGDF_ASSERT(m_ptr != nullptr);
85  GraphObjectPtr ptr = m_ptr;
86  m_ptr = m_ptr->pred();
87  return ptr;
88  }
89 };
90 
91 template<class ArrayType, bool isConst> class GraphArrayIteratorBase;
94 
95 template<class ArrayType, bool isConst> class GraphArrayIteratorBase {
96  friend class GraphArrayIteratorBase<ArrayType, true>;
97 
98 public:
100  using key_type = typename ArrayType::key_type;
105 
108  : m_key(nullptr), m_array(nullptr) {}
109 
112  : m_key(key), m_array(a) { }
113 
117  : GraphArrayIteratorBase(iter.m_key, iter.m_array) { }
118 
121  m_key = iter.m_key;
122  m_array = iter.m_array;
123  return *this;
124  }
125 
127  key_type key() const { return m_key; }
128 
130  value_type &value() const { return (*m_array)[m_key]; }
131 
133  value_type &operator*() const { return (*m_array)[m_key]; }
134 
137  return m_key == iter.m_key && m_array == iter.m_array;
138  }
139 
142  return !operator==(iter);
143  }
144 
147  OGDF_ASSERT(m_key != nullptr);
148  m_key = ArrayType::findSuccKey(m_key);
149  return *this;
150  }
151 
155  m_key = ArrayType::findSuccKey(m_key);
156  return iter;
157  }
158 
161  OGDF_ASSERT(m_key != nullptr);
162  m_key = ArrayType::findPredKey(m_key);
163  return *this;
164  }
165 
169  m_key = ArrayType::findPredKey(m_key);
170  return iter;
171  }
172 
173 private:
176 };
177 
178 }
179 }
key_type key() const
Index in m_array.
key_type m_key
Index in m_array.
GraphArrayIteratorBase< ArrayType, isConst > & operator++()
Increment operator (prefix).
GraphArrayIteratorBase< ArrayType, isConst > operator++(int)
Increment operator (postfix).
GraphIterator(GraphObjectPtr ptr)
GraphIterator< GraphObjectPtr > & operator--()
Decrement operator (prefix).
value_type & value() const
Value of m_array at index m_key.
array_pointer_type m_array
The array.
bool operator!=(const GraphArrayIteratorBase< ArrayType, isConst > &iter) const
Inequality operator.
typename std::conditional< isConst, const ArrayType *, ArrayType * >::type array_pointer_type
Type of the array.
bool operator!=(const GraphIterator< GraphObjectPtr > &other) const
GraphArrayIteratorBase(key_type key, array_pointer_type a)
Constructor.
value_type & operator*() const
Value of m_array at index m_key.
typename ArrayType::key_type key_type
Index type of the associated array.
GraphArrayIteratorBase< ArrayType, isConst > & operator--()
Decrement operator (prefix).
GraphIterator< GraphObjectPtr > operator++(int)
Increment operator (postfix).
GraphArrayIteratorBase(const GraphArrayIteratorBase< ArrayType, isArgConst > &iter)
Constructor.
typename std::conditional< isConst, const typename ArrayType::value_type, typename ArrayType::value_type >::type value_type
Value type of the associated array.
bool operator==(const GraphArrayIteratorBase< ArrayType, isConst > &iter) const
Equality operator.
GraphArrayIteratorBase< ArrayType, isConst > operator--(int)
Decrement operator (postfix).
bool operator==(const GraphIterator< GraphObjectPtr > &other) const
The namespace for all OGDF objects.
GraphIterator< GraphObjectPtr > & operator++()
Increment operator (prefix).
GraphArrayIteratorBase< ArrayType, isConst > & operator=(const GraphArrayIteratorBase< ArrayType, isConst > &iter)
Copy assignment operator.
GraphIterator< GraphObjectPtr > operator--(int)
Decrement operator (postfix).
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41