Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53547 - in sandbox/SOC/2009/function_graph: boost/function_graph libs/test
From: mlopez7_at_[hidden]
Date: 2009-06-01 12:11:58


Author: lopezeant
Date: 2009-06-01 12:11:58 EDT (Mon, 01 Jun 2009)
New Revision: 53547
URL: http://svn.boost.org/trac/boost/changeset/53547

Log:
cleaned file, constructor fixed
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 38 ++++++++++++++++++++++----------------
   sandbox/SOC/2009/function_graph/libs/test/test1.cpp | 39 +++++++++++++++++++--------------------
   2 files changed, 41 insertions(+), 36 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-01 12:11:58 EDT (Mon, 01 Jun 2009)
@@ -35,13 +35,23 @@
     typedef typename function_type::first_argument_type vertex_type;
     //typedef typename function_type::second_argument_type second_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_edge_function(function_type edge_function)
+ void set_function(function_type edge_function)
     { edge_ = edge_function; }
+
     function_type edge_;
 };
 
@@ -54,7 +64,7 @@
  * variant will be instantiated for meaningless types such as graph<int>.
  * Obviously, that should fail.
  */
-//template <typename T> struct function_graph { };
+template <typename T> struct function_graph { };
 
 /**
  * function_graph is a class designed to handle implicit graphs and more.
@@ -65,11 +75,10 @@
  * is part of the interface. Paired with it is the default constructor.
  */
 template <typename Edge, typename Vertex>
-struct function_graph //<function<Edge(Vertex, Vertex)> >
- : private function_graph_base <function <Edge(Vertex, Vertex)> >
+struct function_graph <function<Edge(Vertex, Vertex)> >
+ : public function_graph_base <function <Edge(Vertex, Vertex)> >
 {
- typedef function_graph_base <function<Edge(Vertex, Vertex)> > Base;
-
+ typedef function_graph_base <function <Edge(Vertex, Vertex)> > Base;
 public:
 
     typedef typename Base::function_type function_type;
@@ -79,26 +88,22 @@
 
     /**
      * Constructor: default
- * @note Exists only when set_edge is used
      */
     function_graph()
     { }
     
     /** Constructor: takes a boost::function or functor */
     function_graph(function_type const& f)
- //: edge_(f)
- { edge_ = f;}
+ : Base(f)
+ { }
     
     
     /** Set the function of the implicit graph */
- using Base::set_edge_function;
+ using Base::set_function;
     
     /** Edge function from Base */
     using Base::edge;
-
-private:
- Base::edge_;
-
+
 private:
 };
 
@@ -108,12 +113,13 @@
  * the form E(U,V) will match the empty class causing compiler errors.
  */
 
-/*template <typename Edge, typename Vertex>
+template <typename Edge, typename Vertex>
 struct function_graph<Edge(Vertex, Vertex)>
     : private function_graph_base< function<Edge(Vertex, Vertex)> >
-{ };*/
+{ };
 
 } // graph namespace
 } // boost namespace
 
 #endif /*FUNCTION_GRAPH_HPP_*/
+

Modified: sandbox/SOC/2009/function_graph/libs/test/test1.cpp
==============================================================================
--- sandbox/SOC/2009/function_graph/libs/test/test1.cpp (original)
+++ sandbox/SOC/2009/function_graph/libs/test/test1.cpp 2009-06-01 12:11:58 EDT (Mon, 01 Jun 2009)
@@ -1,8 +1,3 @@
-/**
- * This file is intended test compilation only.
- */
-
-
 #include <iostream>
 #include <boost/function.hpp>
 #include <functional>
@@ -10,26 +5,30 @@
 #include <vector>
 #include "function_graph.hpp"
 
-// test boost function
-struct int_less_than {
- bool operator()(int a, int b) { return a < b; }
+template <typename T>
+struct less_than {
+ bool operator()(T a, T b) { return a < b; }
 };
 
 int main()
 {
- // create two boost functions
- boost::function2<bool,int,int> h = int_less_than();
- boost::function2<bool,int,int> g = int_less_than();
-
- // test constructor
- boost::graph::function_graph<bool, int> implicitG1(h);
-
- // set the edge function
- implicitG1.set_edge_function(g);
-
- // test the edge function
- implicitG1.edge(1,2);
+ ////////
+ // Create a boost function and function graph.
+ typedef boost::function<bool(int,int)> function_type;
+ typedef boost::graph::function_graph<function_type> graph;
+ function_type f = less_than<int>();
+ function_type g = less_than<int>();
+ graph funcGraph(f);
+
+ ////////
+ // Set a new function to the graph.
+ funcGraph.set_function(g);
     
+ ////////
+ // Check the edge output.
+ std::cout << "2 < 1 check ";
+ if(funcGraph.edge(2,1)) std::cout << "passes." << "\n";
+ else std::cout << "fails." << "\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