Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54841 - in sandbox/SOC/2009/function_graph: boost/function_graph libs/test
From: mlopez7_at_[hidden]
Date: 2009-07-09 16:15:11


Author: lopezeant
Date: 2009-07-09 16:15:11 EDT (Thu, 09 Jul 2009)
New Revision: 54841
URL: http://svn.boost.org/trac/boost/changeset/54841

Log:
Cleaning iterators.

Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 459 ++++++++++++++++++++++-----------------
   sandbox/SOC/2009/function_graph/libs/test/test3.cpp | 19 +
   2 files changed, 272 insertions(+), 206 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-07-09 16:15:11 EDT (Thu, 09 Jul 2009)
@@ -24,6 +24,9 @@
 
 namespace boost {
 
+template<typename Graph> struct function_graph_in_edge_iterator;
+//template<typename Graph> struct function_graph_out_edge_iterator;
+
 /** @name Domain Tags
  * @description Traits that identify the function_graph as either having a
  * finite domain, a range, or having an infinite domain, no range.
@@ -152,149 +155,6 @@
 
 
 
-/** @name In-Edge Iterator
- * @description Iterates through the in edges of a vertex.
- */
-
-template<typename Function, typename Edge, typename Range>
-struct function_graph_in_edge_iterator {
-private:
- typedef function_graph_in_edge_iterator<Function, Edge, Range> This;
-
-public:
- typedef Range vertex_iterator_range;
- typedef typename range_iterator<vertex_iterator_range>::type
- vertex_iterator;
- typedef Edge edge_descriptor;
- typedef Function function_type;
-
- /** Iterator traits */
- typedef std::input_iterator_tag iterator_category;
- typedef edge_descriptor value_type;
- typedef std::size_t different_type;
- typedef value_type* pointer;
- typedef value_type& reference;
-
- /** @internal Constructors */
- //@{
- function_graph_in_edge_iterator(function_type const& f,
- vertex_iterator const& v,
- vertex_iterator const& v_begin,
- vertex_iterator const& v_end)
- : edge_(f),
- vertex_(v),
- vertex_begin_(v_begin),
- vertex_end_(v_end)
- { };
-
- // Copy constructor
- function_graph_in_edge_iterator(This const& cp)
- : edge_(cp.edge_),
- vertex_(cp.vertex_),
- vertex_begin_(cp.vertex_begin_),
- vertex_end_(cp.vertex_end_)
- { };
- //@}
-
- /** Input Iterator operator overloads */
- function_graph_in_edge_iterator& operator++()
- {
- // Cycle through the range until an edge is found,
- // or the end of the list is found
- do {
- ++vertex_begin_;
- } while((vertex_begin_ != vertex_end_) &&
- !detail::bind_edge(edge_(vertex_begin_, vertex_),
- vertex_begin_, vertex_).second);
-
- return *this;
- }
-
- edge_descriptor operator*()
- {
- return edge_descriptor(edge_(*vertex_begin_, *vertex_),
- *vertex_begin_,
- *vertex_);
- }
-
- function_type edge_;
- vertex_iterator vertex_;
- vertex_iterator vertex_begin_;
- vertex_iterator vertex_end_;
-};
-
-
-
-/** @name Out-Edge Iterator
- * @description Iterates through the in edges of a vertex.
- */
-
-template<typename Function, typename Edge, typename Range>
-struct function_graph_out_edge_iterator {
-private:
- typedef function_graph_out_edge_iterator<Function, Edge, Range> This;
-
-public:
- typedef Range vertex_iterator_range;
- typedef typename range_iterator<vertex_iterator_range>::type
- vertex_iterator;
- typedef Edge edge_descriptor;
- typedef Function function_type;
-
- /** Iterator traits */
- typedef std::input_iterator_tag iterator_category;
- typedef edge_descriptor value_type;
- typedef std::size_t different_type;
- typedef value_type* pointer;
- typedef value_type& reference;
-
- /** @internal Constructors */
- //@{
- function_graph_out_edge_iterator(function_type const& f,
- vertex_iterator const& v,
- vertex_iterator const& v_begin,
- vertex_iterator const& v_end)
- : edge_(f),
- vertex_(v),
- vertex_begin_(v_begin),
- vertex_end_(v_end)
- { };
-
- // Copy constructor
- function_graph_out_edge_iterator(This const& cp)
- : edge_(cp.edge_),
- vertex_(cp.vertex_),
- vertex_begin_(cp.vertex_begin_),
- vertex_end_(cp.vertex_end_)
- { };
- //@}
-
- /** Input Iterator operator overloads */
- function_graph_out_edge_iterator& operator++()
- {
- // Cycle through the range until an edge is found,
- // or the end of the list is found
- do {
- ++vertex_begin_;
- } while((vertex_begin_ != vertex_end_) &&
- !edge_(*vertex_, *vertex_begin_));
-
- return *this;
- }
-
- edge_descriptor operator*()
- {
- return edge_descriptor(edge_(*vertex_, *vertex_begin_),
- *vertex_begin_,
- *vertex_);
- }
-
- function_type edge_;
- vertex_iterator vertex_;
- vertex_iterator vertex_begin_;
- vertex_iterator vertex_end_;
-};
-
 
 /** @name Function Graph
  * @description function_graph is a data structure that implements implicit
@@ -340,16 +200,12 @@
     typedef Range vertex_iterator_range;
     typedef typename range_iterator<vertex_iterator_range>::type
                          vertex_iterator;
- typedef function_graph_in_edge_iterator<
- function_type,
- edge_descriptor,
+ typedef function_graph_in_edge_iterator<This> in_edge_iterator;
+ /*typedef function_graph_out_edge_iterator<
+ result_type,
+ vertex_descriptor,
                 vertex_iterator_range
- > in_edge_iterator;
- typedef function_graph_out_edge_iterator<
- function_type,
- edge_descriptor,
- vertex_iterator_range
- > out_edge_iterator;
+ > out_edge_iterator;*/
     typedef finite_domain_tag domain_category;
 
     /** Constructor: takes a functor and range */
@@ -357,7 +213,14 @@
         : Base(f, r)
     { }
 
- using Base::edge_;
+ // @todo This must include the edge and the range
+ bool operator==(This const& rhs)
+ { return range_ == rhs.range_; }
+
+ bool operator!=(This const& rhs)
+ { return !(*this == rhs); }
+
+ using Base::edge;
     using Base::range_;
 };
 
@@ -394,6 +257,8 @@
     function_graph(function_type const& f)
         : Base(f)
     { }
+
+ using Base::edge;
 };
 
 /*template <typename Result, typename Vertex>
@@ -403,7 +268,6 @@
 
 
 
-
 /** source(e, g) and target(e, g) are part of the incedence graph concept. */
 
 template <typename Result, typename Vertex, typename Range>
@@ -418,60 +282,9 @@
 
 
 
-/** in_edges(v, g) and out_edges(u, g)
- * @note This is a rough draft for testing purposes and readability. There will
- * be improvements later.
- */
-
 #define FUNC_GRAPH \
     function_graph<function<Result(Vertex, Vertex)>, Range>
 
-template <typename Result, typename Vertex, typename Range>
-std::pair<
- typename FUNC_GRAPH::in_edge_iterator,
- typename FUNC_GRAPH::in_edge_iterator
->
-in_edges(typename FUNC_GRAPH::vertex_descriptor const& v, FUNC_GRAPH const& g)
-{
- 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 = begin(g.range_);
- vertex_iterator vertex_end = end(g.range_);
- while((first_vertex_pair != vertex_end) || !g.edge_(first_vertex_pair, v))
- { ++first_vertex_pair; }
- in_edge_iterator in_edge_begin(first_vertex_pair, v);
- in_edge_iterator in_edge_end(vertex_end, v);
-
- return std::make_pair(in_edge_begin, in_edge_end);
-}
-
-template <typename Result, typename Vertex, typename Range>
-std::pair<
- typename FUNC_GRAPH::out_edge_iterator,
- typename FUNC_GRAPH::out_edge_iterator
->
-out_edges(typename FUNC_GRAPH::vertex_descriptor const& u, FUNC_GRAPH const& g)
-{
- typedef FUNC_GRAPH Graph;
- typedef typename Graph::out_edge_iterator out_edge_iterator;
- typedef typename Graph::vertex_iterator vertex_iterator;
- typedef std::pair<out_edge_iterator, out_edge_iterator> iter_range;
-
- vertex_iterator first_vertex_pair = begin(g.range_);
- vertex_iterator vertex_end = end(g.range_);
- while((first_vertex_pair != vertex_end) || !g.edge_(first_vertex_pair, u))
- { ++first_vertex_pair; }
- out_edge_iterator out_edge_begin(first_vertex_pair, u);
- out_edge_iterator out_edge_end(vertex_end, u);
-
- return std::make_pair(out_edge_begin, out_edge_end);
-}
-
-
-
 /** Degree functions */
 
 template<typename Result, typename Vertex, typename Range>
@@ -553,9 +366,243 @@
     return detail::bind_edge(result, u, v);
 }
 
-#undef FUNC_GRAPH
+/*
+template <typename Graph>
+std::pair<typename Graph::edge_descriptor, bool>
+edge(typename Graph::vertex_descriptor u,
+ typename Graph::vertex_descriptor v,
+ Graph const& g)
+{
+ typedef Graph graph_type;
+ typedef typename Graph::result_type result_type;
+ result_type result = g.edge(u, v);
+ return detail::bind_edge(result, u, v);
+}
+*/
+
 //@}
 
+/** in_edges(v, g) and out_edges(u, g)
+ * @note This is a rough draft for testing purposes and readability. There will
+ * be improvements later.
+ */
+
+template <typename Result, typename Vertex, typename Range>
+std::pair<
+ typename FUNC_GRAPH::in_edge_iterator,
+ typename FUNC_GRAPH::in_edge_iterator
+>
+in_edges(typename FUNC_GRAPH::vertex_descriptor const& v, FUNC_GRAPH const& g)
+{
+ 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 vertex_begin = begin(g.range_);
+ vertex_iterator vertex_end = end(g.range_);
+ while((vertex_begin != vertex_end) || !edge(*vertex_begin, v, g).second)
+ { ++vertex_begin; }
+ in_edge_iterator in_edge_begin(g, v, vertex_begin, vertex_end);
+ in_edge_iterator in_edge_end(g, v, vertex_end, vertex_end);
+
+ return std::make_pair(in_edge_begin, in_edge_end);
+}
+
+template <typename Result, typename Vertex, typename Range>
+std::pair<
+ typename FUNC_GRAPH::out_edge_iterator,
+ typename FUNC_GRAPH::out_edge_iterator
+>
+out_edges(typename FUNC_GRAPH::vertex_descriptor const& u, FUNC_GRAPH const& g)
+{
+ typedef FUNC_GRAPH Graph;
+ typedef typename Graph::out_edge_iterator out_edge_iterator;
+ typedef typename Graph::vertex_iterator vertex_iterator;
+ typedef std::pair<out_edge_iterator, out_edge_iterator> iter_range;
+
+ vertex_iterator first_vertex_pair = begin(g.range_);
+ vertex_iterator vertex_end = end(g.range_);
+ while((first_vertex_pair != vertex_end) || !g.edge_(first_vertex_pair, u))
+ { ++first_vertex_pair; }
+ out_edge_iterator out_edge_begin(first_vertex_pair, u);
+ out_edge_iterator out_edge_end(vertex_end, u);
+
+ return std::make_pair(out_edge_begin, out_edge_end);
+}
+
+#undef FUNC_GRAPH
+
+
+/** @name In-Edge Iterator
+ * @description Iterates through the in edges of a vertex.
+ */
+
+template<typename Graph>
+struct function_graph_in_edge_iterator {
+private:
+ typedef function_graph_in_edge_iterator<Graph> This;
+
+public:
+ typedef Graph graph_type;
+ typedef typename graph_type::vertex_iterator vertex_iterator;
+ typedef typename graph_type::edge_descriptor edge_descriptor;
+ typedef typename graph_type::vertex_descriptor vertex_descriptor;
+ typedef typename graph_type::function_type function_type;
+
+ /** Iterator traits */
+ typedef std::input_iterator_tag iterator_category;
+ typedef edge_descriptor value_type;
+ typedef std::size_t different_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ /** @internal Constructors */
+ //@{
+
+ function_graph_in_edge_iterator(graph_type const& g,
+ vertex_descriptor const& v,
+ vertex_iterator const& v_begin,
+ vertex_iterator const& v_end)
+ : g_(g),
+ vertex_(v),
+ vertex_begin_(v_begin),
+ vertex_end_(v_end)
+ { };
+
+ // Copy constructor
+ function_graph_in_edge_iterator(This const& cp)
+ : g_(cp.g_),
+ vertex_(cp.vertex_),
+ vertex_begin_(cp.vertex_begin_),
+ vertex_end_(cp.vertex_end_)
+ { };
+ //@}
+
+ /** Input Iterator operator overloads */
+ This& operator++()
+ {
+ // Cycle through the range until an edge is found,
+ // or the end of the list is found
+ do {
+ ++vertex_begin_;
+ } while((vertex_begin_ != vertex_end_) &&
+ !edge(*vertex_begin_, vertex_, g_).second);
+
+ return *this;
+ }
+
+ edge_descriptor operator*()
+ { return edge_descriptor(edge(*vertex_begin_, vertex_, g_).first); }
+
+ /*bool operator==(This const& rhs)
+ {
+ return g_ == true//rhs.g_ && vertex_ == rhs.vertex_ &&
+ vertex_begin_ == rhs.vertex_begin_ &&
+ vertex_end_ == rhs.vertex_end_*/;
+ /*}
+ bool operator!=(This const& rhs)
+ { return !(*this == rhs); }*/
+
+
+ graph_type const& g_;
+ vertex_descriptor vertex_;
+ vertex_iterator vertex_begin_;
+ vertex_iterator vertex_end_;
+};
+
+template<typename Graph>
+bool operator==(function_graph_in_edge_iterator<Graph> const& lhs,
+ function_graph_in_edge_iterator<Graph> const& rhs)
+{
+ return lhs.vertex_ == rhs.vertex_ &&
+ lhs.vertex_begin_ == rhs.vertex_begin_ &&
+ lhs.vertex_end_ == rhs.vertex_end_;
+}
+
+template<typename Graph>
+bool operator!=(function_graph_in_edge_iterator<Graph> const& lhs,
+ function_graph_in_edge_iterator<Graph> const& rhs)
+{
+ return !(lhs.vertex_ == rhs.vertex_ &&
+ lhs.vertex_begin_ == rhs.vertex_begin_ &&
+ lhs.vertex_end_ == rhs.vertex_end_);
+}
+
+
+
+/** @name Out-Edge Iterator
+ * @description Iterates through the in edges of a vertex.
+ */
+
+template<typename Function, typename Edge, typename Range>
+struct function_graph_out_edge_iterator {
+private:
+ typedef function_graph_out_edge_iterator<Function, Edge, Range> This;
+
+public:
+ typedef Range vertex_iterator_range;
+ typedef typename range_iterator<vertex_iterator_range>::type
+ vertex_iterator;
+ typedef Edge edge_descriptor;
+ typedef Function function_type;
+
+ /** Iterator traits */
+ typedef std::input_iterator_tag iterator_category;
+ typedef edge_descriptor value_type;
+ typedef std::size_t different_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ /** @internal Constructors */
+ //@{
+ function_graph_out_edge_iterator(function_type const& f,
+ vertex_iterator const& v,
+ vertex_iterator const& v_begin,
+ vertex_iterator const& v_end)
+ : edge_(f),
+ vertex_(v),
+ vertex_begin_(v_begin),
+ vertex_end_(v_end)
+ { };
+
+ // Copy constructor
+ function_graph_out_edge_iterator(This const& cp)
+ : edge_(cp.edge_),
+ vertex_(cp.vertex_),
+ vertex_begin_(cp.vertex_begin_),
+ vertex_end_(cp.vertex_end_)
+ { };
+ //@}
+
+ /** Input Iterator operator overloads */
+ function_graph_out_edge_iterator& operator++()
+ {
+ // Cycle through the range until an edge is found,
+ // or the end of the list is found
+ do {
+ ++vertex_begin_;
+ } while((vertex_begin_ != vertex_end_) &&
+ !edge_(*vertex_, *vertex_begin_));
+
+ return *this;
+ }
+
+ edge_descriptor operator*()
+ {
+ return edge_descriptor(edge_(vertex_, *vertex_begin_),
+ *vertex_begin_,
+ *vertex_);
+ }
+
+ function_type edge_;
+ vertex_iterator vertex_;
+ vertex_iterator vertex_begin_;
+ vertex_iterator vertex_end_;
+};
+
+
+
 } // boost namespace
 
 #endif /*FUNCTION_GRAPH_HPP_*/

Modified: sandbox/SOC/2009/function_graph/libs/test/test3.cpp
==============================================================================
--- sandbox/SOC/2009/function_graph/libs/test/test3.cpp (original)
+++ sandbox/SOC/2009/function_graph/libs/test/test3.cpp 2009-07-09 16:15:11 EDT (Thu, 09 Jul 2009)
@@ -38,6 +38,10 @@
     typedef boost::function<long(long, long)> weighted_func;
     typedef boost::function_graph<boolean_func, iterator_range> boolean_graph;
     typedef boost::function_graph<weighted_func, iterator_range> weighted_graph;
+ typedef std::pair<
+ boolean_graph::in_edge_iterator,
+ boolean_graph::in_edge_iterator
+ > in_edge_range;
 
     ////////
     // Create function graphs
@@ -47,6 +51,11 @@
                                 std::make_pair(numbers.begin(), numbers.end()));
 
     ////////
+ // Check graph boolean operators
+ assert(booleanGraph == booleanGraph);
+ assert(weightedGraph == weightedGraph);
+
+ ////////
     // Check vertices(g)
     iterator_range correctRange = std::make_pair(numbers.begin(),
                                                     numbers.end());
@@ -61,6 +70,16 @@
 
     ////////
     // Check in edges
+ std::vector<long>::iterator aVertex = ++numbers.begin(); // aVector = 572
+ in_edge_range in_edges_bool = in_edges(*aVertex, booleanGraph);
+ // print all in_edges
+ while(in_edges_bool.first != in_edges_bool.second)
+ {
+ ++in_edges_bool.first;
+ }
+ //iterator_range in_edges_wght = in_edges(*aVertex, weightedGraph);
+
+ std::cerr << "\nCompiled - What? It worked?\n\n";
 
     return 0;
 }


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