|
Boost-Commit : |
From: asutton_at_[hidden]
Date: 2008-05-30 08:31:04
Author: asutton
Date: 2008-05-30 08:31:03 EDT (Fri, 30 May 2008)
New Revision: 45941
URL: http://svn.boost.org/trac/boost/changeset/45941
Log:
Finished making the indexed_edge_iterator a real random access iterator.
Text files modified:
sandbox/SOC/2008/graphs/boost/graphs/adjacency_list/es/indexed_edge_iterator.hpp | 154 ++++++++++++++++++++++++++++++++-------
1 files changed, 125 insertions(+), 29 deletions(-)
Modified: sandbox/SOC/2008/graphs/boost/graphs/adjacency_list/es/indexed_edge_iterator.hpp
==============================================================================
--- sandbox/SOC/2008/graphs/boost/graphs/adjacency_list/es/indexed_edge_iterator.hpp (original)
+++ sandbox/SOC/2008/graphs/boost/graphs/adjacency_list/es/indexed_edge_iterator.hpp 2008-05-30 08:31:03 EDT (Fri, 30 May 2008)
@@ -11,6 +11,9 @@
/**
* The indexed edge iterator provides an edge iterator for stores whose
* descriptors cannot be pointers (i.e., vectors).
+ *
+ * Because the underlying store for this iterator is a vector, this is a random
+ * access iterator.
*/
template <typename Store>
class indexed_edge_iterator
@@ -20,46 +23,139 @@
typedef typename Store::value_type edge_type;
typedef typename edge_type::descriptor_type edge_descriptor;
+ typedef typename iterator::iterator_category iterator_category;
+ typedef typename iterator::difference_type difference_type;
typedef edge_descriptor value_type;
typedef edge_descriptor reference;
typedef edge_descriptor pointer;
- indexed_edge_iterator()
- : store(0)
- , iter()
- { }
-
- indexed_edge_iterator(indexed_edge_iterator const& x)
- : store(x.store)
- , iter(x.iter)
- { }
-
- indexed_edge_iterator(Store const& s, iterator const& x)
- : store(&s)
- , iter(x)
- { }
-
- indexed_edge_iterator& operator++()
- {
- ++iter;
- return *this;
- }
+ inline indexed_edge_iterator();
+ inline indexed_edge_iterator(indexed_edge_iterator const& x);
+ inline indexed_edge_iterator(Store const& s, iterator const& x);
+
+ inline indexed_edge_iterator& operator=(indexed_edge_iterator const& x);
+ inline indexed_edge_iterator& operator+=(difference_type n);
+ inline indexed_edge_iterator& operator-=(difference_type n);
+ inline indexed_edge_iterator& operator++();
+ inline indexed_edge_iterator& operator--();
+
+ inline indexed_edge_iterator operator+(difference_type n) const;
+ inline indexed_edge_iterator operator-(difference_type n) const;
+ inline difference_type operator-(indexed_edge_iterator const& x) const;
- // The returned descriptor is simply the distance from the beginning of
- // the underlying store to the end.
- reference operator*()
- { return std::distance(store->begin(), iter); }
-
- bool operator==(indexed_edge_iterator const& x) const
- { return (store == x.store) && (iter == x.iter); }
+ inline reference operator*();
- bool operator!=(indexed_edge_iterator const& x) const
- { return (store == x.store) && (iter != x.iter); }
+ inline bool operator==(indexed_edge_iterator const& x) const;
+ inline bool operator!=(indexed_edge_iterator const& x) const;
+private:
Store const* store;
iterator iter;
};
+template <typename S>
+indexed_edge_iterator<S>::indexed_edge_iterator()
+ : store(0)
+ , iter()
+{ }
+
+template <typename S>
+indexed_edge_iterator<S>::indexed_edge_iterator(indexed_edge_iterator const& x)
+ : store(x.store)
+ , iter(x.iter)
+{ }
+
+template <typename S>
+indexed_edge_iterator<S>::indexed_edge_iterator(S const& s, iterator const& x)
+ : store(&s)
+ , iter(x)
+{ }
+
+template <typename S>
+indexed_edge_iterator<S>&
+indexed_edge_iterator<S>::operator=(indexed_edge_iterator const& x)
+{
+ iter = x.iter;
+ store = x.store;
+ return &this;
+}
+
+template <typename S>
+indexed_edge_iterator<S>&
+indexed_edge_iterator<S>::operator+=(difference_type n)
+{
+ iter += n;
+ return &this;
+}
+
+template <typename S>
+indexed_edge_iterator<S>&
+indexed_edge_iterator<S>::operator-=(difference_type n)
+{
+ iter -= n;
+ return &this;
+}
+
+template <typename S>
+indexed_edge_iterator<S>&
+indexed_edge_iterator<S>::operator++()
+{
+ ++iter;
+ return *this;
+}
+
+template <typename S>
+indexed_edge_iterator<S>&
+indexed_edge_iterator<S>::operator--()
+{
+ --iter;
+ return *this;
+}
+
+template <typename S>
+indexed_edge_iterator<S>
+indexed_edge_iterator<S>::operator+(difference_type n) const
+{
+ return iter + n;
+}
+
+template <typename S>
+indexed_edge_iterator<S>
+indexed_edge_iterator<S>::operator-(difference_type n) const
+{
+ return iter - n;
+}
+
+template <typename S>
+typename indexed_edge_iterator<S>::difference_type
+indexed_edge_iterator<S>::operator-(indexed_edge_iterator const& x) const
+{
+ return iter - x;
+}
+
+template <typename S>
+typename indexed_edge_iterator<S>::reference
+indexed_edge_iterator<S>::operator*()
+{
+ // The returned descriptor is simply the distance from the beginning of
+ // the underlying store to the end.
+ return std::distance(store->begin(), iter);
+}
+
+template <typename S>
+bool
+indexed_edge_iterator<S>::operator==(indexed_edge_iterator const& x) const
+{
+ return (store == x.store) && (iter == x.iter);
+}
+
+template <typename S>
+bool
+indexed_edge_iterator<S>::operator!=(indexed_edge_iterator const& x) const
+{
+ return (store == x.store) && (iter != x.iter);
+}
+
} /* namespace adj_list */
} /* namespace graphs */
} /* namespace boost */
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk