|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53589 - sandbox/SOC/2009/function_graph/boost/function_graph
From: mlopez7_at_[hidden]
Date: 2009-06-02 21:41:20
Author: lopezeant
Date: 2009-06-02 21:41:20 EDT (Tue, 02 Jun 2009)
New Revision: 53589
URL: http://svn.boost.org/trac/boost/changeset/53589
Log:
Currently in the middle of adapting adjacency graph concept.
Text files modified:
sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 80 +++++++++++++++++++++++++++-------------
1 files changed, 54 insertions(+), 26 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-02 21:41:20 EDT (Tue, 02 Jun 2009)
@@ -1,10 +1,10 @@
/**
* Copyright (C) 2009
* Michael Lopez
- *
+ *
* Issued under Boost Software License - Version 1.0
* http://www.boost.org/LICENSE_1_0.txt
- *
+ *
*/
#ifndef FUNCTION_GRAPH_HPP_
@@ -14,6 +14,7 @@
#include <boost/function.hpp>
#include <boost/function_types/function_arity.hpp>
#include <utility>
+#include <boost/optional/optional_fwd.hpp>
namespace boost {
@@ -24,31 +25,33 @@
*/
template <typename Func>
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;
-
+
/** Constructor - Default */
function_graph_base()
{ }
-
+
/** Constructors to allow for initialization of edge */
function_graph_base(function_type const& f)
: edge_(f)
{ }
-
+
// Allow access to the function edge_ holds, not edge_ itself.
edge_type edge(vertex_type v1, vertex_type v2)
{ return edge_(v1, v2); }
-
+
// Set the edge_ function
void set_function(function_type edge_function)
{ edge_ = edge_function; }
-
+
function_type edge_;
};
+
+
/**
* Empty function graph prevents instantiations such as function_graph<int> and
* function_graph<bool (int, int)>.
@@ -58,10 +61,10 @@
/**
* function_graph is a data structure that implements implicit graphs and more.
* Better documentation and explanation of the data structure to come.
- *
- * @internal The typical user of function graph may not need to change edge
- * function during execution. However, since the code needed is minute, set_edge
- * is part of the interface. Paired with it is the default constructor.
+ *
+ * @internal The typical user of function graph may not need to change edge
+ * 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)> >
@@ -69,7 +72,7 @@
{
typedef function_graph_base <function <Edge(Vertex, Vertex)> > Base;
public:
-
+
typedef typename Base::function_type function_type;
typedef typename Base::vertex_type vertex_descriptor;
typedef typename Base::edge_type edge_descriptor;
@@ -81,18 +84,19 @@
function_graph()
: Base()
{ }
-
+
/** Constructor: takes a boost::function or functor */
function_graph(function_type const& f)
: Base(f)
{ }
-
- /** Set the function of the implicit graph */
+
+ /** Set the function of the implicit graph */
using Base::set_function;
-
-private:
+
/** Edge function from Base */
using Base::edge;
+
+private:
};
/**
@@ -106,13 +110,38 @@
: private function_graph_base <function<Edge(Vertex, Vertex)> >
{ };
+
+
/**
- * Direct Edge Access - Part of the adjacency matrix concept
- * http://www.boost.org/doc/libs/1_39_0/libs/graph/doc/AdjacencyMatrix.html
- */
+ * 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>.
+ */
+
+// Method of dealing with the different types of edge returns.
+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); }
+// optional is being considered
+/*
+template<>
+std::pair<Edge, bool> get_edge_pair<optional<?> >(optional<?> edge);*/
+
+}
+
+
+} // detail namespace
+
template <typename Edge, typename Vertex>
std::pair<typename function_graph<function<Edge(Vertex, Vertex)> >
- ::edge_descriptor, // It would look cleaner to use Edge and Vertex
+ ::edge_descriptor,
bool>
edge(typename function_graph<function<Edge(Vertex, Vertex)> >
::vertex_descriptor u,
@@ -120,10 +149,9 @@
::vertex_descriptor v,
function_graph<function<Edge(Vertex, Vertex)> > const& g)
{
- // Issue: Edge does not necessarily yield a false. The edge function needs
- // to account for this and should return the pair.
- //bool exists = function_graph<function<Edge(Vertex, Vertex)> >::edge(u, v)
- //return std::make_pair(/* */, exists);
+ typedef function_graph<function<Edge(Vertex, Vertex)> >::edge_descriptor
+ edge_descriptor;
+ detail::get_edge_pair
}
} // 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