|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53319 - sandbox/SOC/2009/function_graph/boost/function_graph
From: mlopez7_at_[hidden]
Date: 2009-05-27 15:17:19
Author: lopezeant
Date: 2009-05-27 15:17:16 EDT (Wed, 27 May 2009)
New Revision: 53319
URL: http://svn.boost.org/trac/boost/changeset/53319
Log:
function_graph uploaded
Added:
sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp (contents, props changed)
- copied, changed from r53290, /sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_functor.hpp
Removed:
sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_function.hpp
sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_functor.hpp
Text files modified:
sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 85 ++++++++++++++++++++++-----------------
1 files changed, 47 insertions(+), 38 deletions(-)
Copied: sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp (from r53290, /sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_functor.hpp)
==============================================================================
--- /sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_functor.hpp (original)
+++ sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp 2009-05-27 15:17:16 EDT (Wed, 27 May 2009)
@@ -1,60 +1,69 @@
-#ifndef FUNCTION_GRAPH_FUNCTOR_HPP_
-#define FUNCTION_GRAPH_FUNCTOR_HPP_
+/**
+ * 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_
+#define FUNCTION_GRAPH_HPP_
#include <boost/function.hpp>
+#include <boost/function_types/function_arity.hpp>
+#include <boost/mpl/if.hpp>
namespace boost { namespace graph {
/**
- * beta of function_graph using functor
- *
+ * function_graph_base handles the edge function. A user can define the function
+ * through a boost::function or a functor, but the user must only have access to
+ * this function through function graph via the function edge.
+ */
+
+template <typename F>
+struct function_graph_base {
+ // If the type F has an arity of 2, then it is the boost function syntax.
+ // Otherwise, this function is either a functor or a boost function that is
+ // already defined.
+ typedef typename mpl::if_c<function_types::function_arity<F>::value == 2,
+ function<F>,
+ F>::type func_type;
+ /** Types are deduced from F */
+
+ /** Edge function that defines the implicit graph */
+ func_type edge;
+};
+
+
+/**
* function_graph is a data structure that creates an implicit graph based on a
* function or functor that is either user defined or from the stl or boost.
*
- * @internal
- * as of current, this data structure acts over a container. The type of the
- * container is immaterial, so long as it uses T least an input iterator.
+ * For a more enlightening explanation, please refer to the documentation.
*
* @todo
- * implement a pointer that will set itself to null if the object it points to
- * is destroyed
- * have type deduced from container
- * implement domains and ranges (given a type and function, but no container)
- * implement an edge iterator
- * implement a function_graph that acts over two sets that may be different
- * types
+ * Supply polished documentation
+ * Implement domain and range
+ * Implement an edge iterator
*/
- /**
- * function_graph - functor version
- */
-template<typename container, template <typename> class functor>
-class function_graph
+template<typename F>
+class function_graph : private function_graph_base<F>
{
- typedef typename container::value_type value_type;
- // functor type is deduced from the container
- // could use better method of deduction
- typedef functor<value_type> functor_type;
-
+ typedef function_graph_base<F> Base;
public:
- /** Constructor - blank */
- function_graph()
- : container_(0) { }
-
- /** Constructor - take the container */
- function_graph(container const& x)
- : container_(&x) { }
+ /** The edge function. */
+ using Base::edge;
- /** edge functor - allows it to act as edge(...) */
-public:
- functor_type edge;
-
-private:
- const container* container_;
};
} // graph namespace
} // boost namespace
-#endif /*FUNCTION_GRAPH_FUNCTOR_HPP_*/
+#endif /*FUNCTION_GRAPH_HPP_*/
+
Deleted: sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_function.hpp
==============================================================================
--- sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_function.hpp 2009-05-27 15:17:16 EDT (Wed, 27 May 2009)
+++ (empty file)
@@ -1,47 +0,0 @@
-#ifndef FUNCTION_GRAPH_FUNCTION_HPP_
-#define FUNCTION_GRAPH_FUNCTION_HPP_
-
-#include <boost/graph/graph_traits.hpp>
-#include <boost/graph/adjacency_list.hpp>
-
-#include <boost/function.hpp>
-
-namespace boost { namespace graph {
-
-/**
- * function_graph - function version
- */
-template<typename container, typename edge_return>
-class function_graph {
- typedef container container_type;
- typedef typename container_type::value_type value_type;
- typedef edge_return edge_return_type;
- typedef boost::function<edge_return_type (value_type, value_type)>
- function_type;
-public:
- /** Constructor - blank */
- function_graph()
- : edge_(0), container_(0) { }
-
- /** Constructor - take a function */
- function_graph(function_type const& f)
- : edge_(f), container_(0) { }
-
- /** Constructor - take a function and a container */
- function_graph(function_type const& f, container_type const& x)
- : edge_(f), container_(&x) { }
-
- /** edge - does the edge exist */
- edge_return_type edge(value_type const& a, value_type const& b)
- { return edge_(a, b); }
-
-private:
- function_type edge_;
- const container_type* container_;
-
-};
-
-} // end graph namespace
-} // end boost naespace
-
-#endif /*FUNCTION_GRAPH_FUNCTION_HPP_*/
Deleted: sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_functor.hpp
==============================================================================
--- sandbox/SOC/2009/function_graph/boost/function_graph/function_graph_functor.hpp 2009-05-27 15:17:16 EDT (Wed, 27 May 2009)
+++ (empty file)
@@ -1,60 +0,0 @@
-#ifndef FUNCTION_GRAPH_FUNCTOR_HPP_
-#define FUNCTION_GRAPH_FUNCTOR_HPP_
-
-#include <boost/function.hpp>
-
-namespace boost { namespace graph {
-
-/**
- * beta of function_graph using functor
- *
- * function_graph is a data structure that creates an implicit graph based on a
- * function or functor that is either user defined or from the stl or boost.
- *
- * @internal
- * as of current, this data structure acts over a container. The type of the
- * container is immaterial, so long as it uses T least an input iterator.
- *
- * @todo
- * implement a pointer that will set itself to null if the object it points to
- * is destroyed
- * have type deduced from container
- * implement domains and ranges (given a type and function, but no container)
- * implement an edge iterator
- * implement a function_graph that acts over two sets that may be different
- * types
- */
-
- /**
- * function_graph - functor version
- */
-template<typename container, template <typename> class functor>
-class function_graph
-{
- typedef typename container::value_type value_type;
- // functor type is deduced from the container
- // could use better method of deduction
- typedef functor<value_type> functor_type;
-
-public:
-
- /** Constructor - blank */
- function_graph()
- : container_(0) { }
-
- /** Constructor - take the container */
- function_graph(container const& x)
- : container_(&x) { }
-
- /** edge functor - allows it to act as edge(...) */
-public:
- functor_type edge;
-
-private:
- const container* container_;
-};
-
-} // graph namespace
-} // boost namespace
-
-#endif /*FUNCTION_GRAPH_FUNCTOR_HPP_*/
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