Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54288 - sandbox/SOC/2009/function_graph/boost/function_graph
From: mlopez7_at_[hidden]
Date: 2009-06-23 15:14:17


Author: lopezeant
Date: 2009-06-23 15:14:16 EDT (Tue, 23 Jun 2009)
New Revision: 54288
URL: http://svn.boost.org/trac/boost/changeset/54288

Log:
In edge iterator and in_edges finished
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 89 ++++++++++++++++++++++++---------------
   1 files changed, 55 insertions(+), 34 deletions(-)

Modified: sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp
==============================================================================
--- sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp (original)
+++ sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp 2009-06-23 15:14:16 EDT (Tue, 23 Jun 2009)
@@ -16,6 +16,7 @@
 #include <utility>
 #include <boost/optional/optional_fwd.hpp>
 #include <boost/range.hpp>
+#include <iterator>
 
 namespace boost {
 
@@ -80,7 +81,42 @@
  * @note The name of this data type is 31 characters long. I need some brevity.
  */
 
-struct function_graph_in_edge_iterator { };
+template<typename Edge, typename Range>
+struct function_graph_in_edge_iterator {
+ typedef Range vertex_iterator_range;
+ typedef typename iterator_range<vertex_iterator_range>::type
+ vertex_iterator;
+ typedef Edge edge_descriptor;
+
+ /** Iterator traits */
+ typedef std::bidirectional_iterator_tag iterator_category;
+ typedef edge_descriptor value_type;
+ typedef std::size_t different_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ /** Default constructor which looks for the first edge. */
+ function_graph_in_edge_iterator()
+ : range_()
+ { };
+
+ /** Constructor taking a vertex range */
+ function_graph_in_edge_iterator(vertex_iterator_range const& cp)
+ : range_(cp)
+ { };
+
+ /** Bidirectional Iterator operator overloads */
+ function_graph_in_edge_iterator& operator++()
+ { };
+
+ function_graph_in_edge_iterator& operator--()
+ { };
+
+ vertex_iterator& operator*()
+ { };
+
+ vertex_iterator_range range_;
+};
 
 
 
@@ -118,17 +154,17 @@
     typedef directed_tag directed_category;
     typedef disallow_parallel_edge_tag edge_parallel_category;
     typedef adjacency_matrix_tag traversal_category;
- typedef Range vertex_iterator_range_type;
- typedef typename range_iterator<vertex_iterator_range_type>::type
+ typedef Range vertex_iterator_range;
+ typedef typename range_iterator<vertex_iterator_range>::type
                          vertex_iterator;
- typedef function_graph_in_edge_iterator in_edge_iterator;
+ typedef function_graph_in_edge_iterator<edge_descriptor,
+ vertex_iterator_range> in_edge_iterator;
 
     /** Constructor: takes a functor and range */
- function_graph(function_type const& f, vertex_iterator_range_type const& r)
+ function_graph(function_type const& f, vertex_iterator_range const& r)
         : Base(f), range_(r)
     { }
 
-private:
     Range range_;
 };
 
@@ -158,28 +194,6 @@
 
 
 
-/** @name make_function_graph
- * Create and return a function_graph object deduced from the function arguments
- * passed to it.
- */
-
-//@{
-template <typename Result, typename Vertex>
-function_graph<function<Result(Vertex, Vertex)>, no_domain>
- make_function_graph(function<Result(Vertex, Vertex)> const& f)
-{
- return function_graph<function<Result(Vertex, Vertex)>, no_domain>(f);
-}
-
-template <typename Result, typename Vertex, typename Range>
-function_graph<function<Result(Vertex, Vertex)>, Range>
- make_function_graph(function<Result(Vertex, Vertex)> const& f,
- Range const& r)
-{
- return function_graph<function<Result(Vertex, Vertex)>, Range>(f,r);
-}
-//@}
-
 /**
  * @note This specialization will match any function of the form E(V,V) and
  * generates the graph over an adapted boost function. Note that functions of
@@ -222,12 +236,19 @@
          Range>::vertex_descriptor const& v,
          function_graph<function<Result(Vertex, Vertex)>, Range> const& g)
 {
- std::pair<typename function_graph<function<Result(Vertex, Vertex)>,
- Range>::in_edge_iterator,
- typename function_graph<function<Result(Vertex, Vertex)>,
- Range>::in_edge_iterator> iter_range;
- // Search for first and last in_edges
- return iter_range;
+ typedef function_graph<function<Result(Vertex, Vertex)>, Range> Graph;
+ typedef typename Graph::in_edge_iterator in_edge_iterator;
+ typedef typename Graph::vertex_iterator vertex_iterator;
+ typedef std::pair<in_edge_iterator, in_edge_iterator> iter_range;
+
+ vertex_iterator first_vertex_pair = boost::begin(g.range_);
+ vertex_iterator vertex_end = boost::end(g.range_);
+ while((first_vertex_pair != vertex_end) || !g.edge_(first_vertex_pair, v))
+ { ++first_vertex_pair; }
+ in_edge_iterator begin(first_vertex_pair, v);
+ in_edge_iterator end(vertex_end, v);
+
+ return std::make_pair(begin, end);
 }
 
 


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