Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53764 - sandbox/SOC/2009/function_graph/boost/function_graph
From: mlopez7_at_[hidden]
Date: 2009-06-08 21:50:46


Author: lopezeant
Date: 2009-06-08 21:50:45 EDT (Mon, 08 Jun 2009)
New Revision: 53764
URL: http://svn.boost.org/trac/boost/changeset/53764

Log:
starting on source function
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 89 ++++++++++++++++++++++++++-------------
   1 files changed, 59 insertions(+), 30 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-08 21:50:45 EDT (Mon, 08 Jun 2009)
@@ -18,6 +18,33 @@
 
 namespace boost {
 
+namespace detail {
+
+/** Edge type */
+template <typename Result, typename Vertex>
+struct func_graph_edge {
+ typedef typename Result result_type;
+ typedef typename Vertex vertex_descriptor;
+
+ func_graph_edge(result_type rslt,
+ vertex_descriptor src,
+ vertex_descriptor trg)
+ : result(rslt), source(src), target(trg)
+ { }
+
+ vertex_descriptor source() const
+ { return source; }
+
+ vertex_descriptor target() const
+ { return target; }
+
+ result_type result;
+ vertex_descriptor source;
+ vertex_descriptor target;
+}
+
+} // detail namespace
+
 /**
  * function_graph_base handles the edge function. A user can define the function
  * as a boost::function, but the user may only have access to this function
@@ -27,8 +54,9 @@
 struct function_graph_base {
 
     typedef Func function_type;
- typedef typename function_type::result_type edge_type;
     typedef typename function_type::first_argument_type vertex_type;
+ typedef typename func_graph_edge<function_type::result_type,
+ vertex_type> edge_type;
 
     /** Constructor - Default */
     function_graph_base()
@@ -40,13 +68,9 @@
     { }
 
     // Allow access to the function edge_ holds, not edge_ itself.
- edge_type edge(vertex_type v1, vertex_type v2)
+ edge_type edge (vertex_type v1, vertex_type v2) const
     { return edge_(v1, v2); }
 
- // Set the edge_ function
- void set_function(function_type edge_function)
- { edge_ = edge_function; }
-
     function_type edge_;
 };
 
@@ -66,11 +90,12 @@
  * function during execution. However, since the code needed is trivial,
  * set_edge is part of the interface. Paired with it is the default constructor.
  */
-template <typename Edge, typename Vertex>
-struct function_graph <function <Edge(Vertex, Vertex)> >
- : public function_graph_base <function <Edge(Vertex, Vertex)> >
+template <typename Result, typename Vertex>
+struct function_graph <function <Result(Vertex, Vertex)> >
+ : public function_graph_base <function <Result(Vertex, Vertex)> >
 {
- typedef function_graph_base <function <Edge(Vertex, Vertex)> > Base;
+ friend
+ typedef function_graph_base <function <Result(Vertex, Vertex)> > Base;
 public:
 
     typedef typename Base::function_type function_type;
@@ -90,13 +115,9 @@
         : Base(f)
     { }
 
- /** Set the function of the implicit graph */
- using Base::set_function;
-
- /** Edge function from Base */
- using Base::edge;
-
 private:
+ /** Edge function from Base */
+ //using Base::edge;
 };
 
 /**
@@ -105,14 +126,22 @@
  * the form E(U,V) will match the empty class causing compiler errors.
  */
 
-template <typename Edge, typename Vertex>
-struct function_graph <Edge(Vertex, Vertex)>
- : private function_graph_base <function<Edge(Vertex, Vertex)> >
+template <typename Result, typename Vertex>
+struct function_graph <Result(Vertex, Vertex)>
+ : private function_graph_base <function<Result(Vertex, Vertex)> >
 { };
 
 
 
 /**
+ * source is part of the incedence graph concept. It returns the
+ */
+
+
+
+
+
+/**
  * edge(u, v, g) is part of the adjacency matrix concept called Direct Edge
  * Access. The function must account for edges that already return. There is
  * specialization to account for functions that use bool and optional<T>.
@@ -122,19 +151,18 @@
 namespace detail {
 
 // Defaults to a function that always returns a value (ie, a complete graph)
-template <typename Edge>
-std::pair<Edge, bool> get_edge_pair(Edge edge)
-{ return std::make_pair(edge, true); }
-// Functions returning a boolean result are of the same
-template<>
-std::pair<bool, bool> get_edge_pair<bool>(bool edge)
-{ return std::make_pair(edge, edge); }
+//template <typename Edge>
+//std::pair<Edge, bool> get_edge_pair(Edge const& edge)
+//{ return std::make_pair(edge, true); }
+// Functions returning a boolean result are redundant
+//template<>
+//std::pair<bool, bool> get_edge_pair<bool>(bool const& edge)
+//{ return std::make_pair(edge, edge); }
 // optional is being considered
 /*
 template<>
 std::pair<Edge, bool> get_edge_pair<optional<?> >(optional<?> edge);*/
     
-}
 
 
 } // detail namespace
@@ -149,9 +177,10 @@
      ::vertex_descriptor v,
      function_graph<function<Edge(Vertex, Vertex)> > const& g)
 {
- typedef function_graph<function<Edge(Vertex, Vertex)> >::edge_descriptor
- edge_descriptor;
- detail::get_edge_pair
+ typedef typename function_graph<function<Edge(Vertex, Vertex)> > graph;
+ typedef typename graph::edge_descriptor;
+ edge_descriptor e = graph.edge(u, v);
+ return detail::get_edge_pair<edge_descriptor>(e);
 }
 
 } // boost namespace


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