Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54314 - in sandbox/SOC/2009/function_graph: boost/function_graph libs/test
From: mlopez7_at_[hidden]
Date: 2009-06-24 16:26:07


Author: lopezeant
Date: 2009-06-24 16:26:06 EDT (Wed, 24 Jun 2009)
New Revision: 54314
URL: http://svn.boost.org/trac/boost/changeset/54314

Log:
In edge iterator operator++ finished.
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 67 +++++++++++++++++++++++++--------------
   sandbox/SOC/2009/function_graph/libs/test/test1.cpp | 11 +++++-
   sandbox/SOC/2009/function_graph/libs/test/test2.cpp | 59 ++++++++++++++++++++--------------
   3 files changed, 86 insertions(+), 51 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-24 16:26:06 EDT (Wed, 24 Jun 2009)
@@ -15,7 +15,7 @@
 #include <boost/function_types/function_arity.hpp>
 #include <utility>
 #include <boost/optional/optional_fwd.hpp>
-#include <boost/range.hpp>
+#include <boost/range/iterator.hpp>
 #include <iterator>
 
 namespace boost {
@@ -88,7 +88,7 @@
 
 public:
     typedef Range vertex_iterator_range;
- typedef typename iterator_range<vertex_iterator_range>::type
+ typedef typename range_iterator<vertex_iterator_range>::type
             vertex_iterator;
     typedef Edge edge_descriptor;
     typedef Function function_type;
@@ -102,39 +102,58 @@
 
     /** Constructors */
     //@{
- function_graph_in_edge_iterator(function_type const& f)
- : edge_(f), range_()
- { };
+ /*function_graph_in_edge_iterator(function_type const& f,
+ vertex_iterator const& v)
+ : edge_(f), vertex_(v), range_()
+ { };*/
 
     function_graph_in_edge_iterator(function_type const& f,
- vertex_iterator_range const& r)
- : edge_(f), range_(r)
+ 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)
     { };
 
     function_graph_in_edge_iterator(This const& cp)
- : edge_(cp.edge_), range_(cp.range_)
+ : edge_(cp.edge_),
+ vertex_(cp.vertex_),
+ vertex_begin_(cp.vertex_begin_),
+ vertex_end_(cp.vertex_end_)
     { };
     //@}
 
     /** Bidirectional Iterator operator overloads */
     function_graph_in_edge_iterator& operator++()
     {
- ++begin(range_);
- return begin(range_);
+ // 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_));
+
+ return *this;
     };
 
     function_graph_in_edge_iterator& operator--()
- { };
+ {
+ return *this;
+ };
 
- edge_descriptor& operator*()
+ edge_descriptor operator*()
     {
- return edge_descriptor(edge_(*begin(range_), *end(range_)),
- begin(range_),
- end(range_));
+ return edge_descriptor(edge_(*vertex_begin_, *vertex_),
+ *vertex_begin_,
+ *vertex_);
     };
 
     function_type edge_;
- vertex_iterator_range range_;
+ vertex_iterator vertex_;
+ vertex_iterator vertex_begin_;
+ vertex_iterator vertex_end_;
 };
 
 
@@ -296,29 +315,29 @@
 
 template <typename Result, typename Vertex>
 std::pair<detail::func_graph_edge<Result, Vertex>, bool>
-bind_edge(Result const& x, Vertex u, Vertex v)
+bind_edge(Result const& r, Vertex u, Vertex v)
 {
- return std::make_pair(detail::func_graph_edge<Result, Vertex>(x, u, v),
+ return std::make_pair(detail::func_graph_edge<Result, Vertex>(r, u, v),
                           true);
 }
 
 template <typename Vertex>
 std::pair<detail::func_graph_edge<bool, Vertex>, bool>
-bind_edge(bool x, Vertex u, Vertex v)
+bind_edge(bool r, Vertex u, Vertex v)
 {
     return std::make_pair(typename detail::func_graph_edge
- <bool, Vertex>(x, u, v),
- x);
+ <bool, Vertex>(r, u, v),
+ r);
 }
 
 // This overload is specific to optional<T>
 template <typename OptType, typename Vertex>
 std::pair<detail::func_graph_edge<optional<OptType>, Vertex>, bool>
-bind_edge(optional<OptType> const& x, Vertex u, Vertex v)
+bind_edge(optional<OptType> const& r, Vertex u, Vertex v)
 {
     return std::make_pair(detail::func_graph_edge
- <optional<OptType>, Vertex>(x, u, v),
- (bool)x);
+ <optional<OptType>, Vertex>(r, u, v),
+ (bool)r);
 }
 
 } // detail namespace

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-24 16:26:06 EDT (Wed, 24 Jun 2009)
@@ -1,5 +1,13 @@
 /**
  * Testing a function that returns a boolean
+ *
+ * Functions used in test:
+ * source(e, g)
+ * target(e, g)
+ * edge(u, v, g)
+ * detail::bind_edge(r, u, v) - general type
+ * detail::bind_edge(r, u, v) - boolean
+ * detail::bind_edge(r, u, v) - optional<T>
  */
 
 #include <iostream>
@@ -13,7 +21,6 @@
 #include <cassert>
 #include <cmath>
 
-
 ////////
 // Boolean function
 template <typename T>
@@ -90,6 +97,6 @@
     assert(source(e3, funcGraph_optional) == r);
     assert(target(e3, funcGraph_optional) == s);
     assert(e2.result_ == -1);
-
+
     return 0;
 }

Modified: sandbox/SOC/2009/function_graph/libs/test/test2.cpp
==============================================================================
--- sandbox/SOC/2009/function_graph/libs/test/test2.cpp (original)
+++ sandbox/SOC/2009/function_graph/libs/test/test2.cpp 2009-06-24 16:26:06 EDT (Wed, 24 Jun 2009)
@@ -1,48 +1,57 @@
 /**
  * Testing a function that has a range
+ *
+ * Functions used in test:
+ * vertices(g)
  */
 
 #include <iostream>
 #include <boost/function.hpp>
 #include <functional>
-#include <algorithm>
 #include <vector>
-//#include <utility>
 #include "function_graph.hpp"
-#include <cmath>
 #include <boost/range.hpp>
 
-////////
-// Boolean function
-template <typename T>
-struct less_than {
- bool operator() (T a, T b) { return a < b; }
-};
 
-int main()
+// print an edge
+template<typename Result, typename Vertex>
+void print_edge(boost::detail::func_graph_edge<Result, Vertex> const& e)
 {
- unsigned int tempArray[5] = {1, 4, 9, 2, 7};
- std::vector<unsigned int> vectorOfInts(tempArray, tempArray + 5);
+ std::cout << "\nEdge:\n" << " Source: " << e.source_ << "\n";
+ std::cout << " Target: " << e.target_ << "\n";
+}
 
+
+int main()
+{
     ////////
- // Create typedefs for functions and function graphs
- typedef boost::function<bool(int,int)> function_boolean;
+ // Typedefs for the graph and iterator range
+ typedef boost::function<bool(int,int)> boolean_function;
     typedef std::pair<std::vector<unsigned int>::iterator,
                       std::vector<unsigned int>::iterator> iterator_range;
- typedef boost::function_graph<function_boolean> G;
- typedef boost::function_graph<function_boolean, iterator_range> GwithRange;
+ typedef boost::function_graph<boolean_function, iterator_range> FuncGraph;
 
     ////////
- // Create functions, graphs and edges
- G funcGraph(std::less<int>());
- GwithRange funcGraphWithRange(less_than<int>(),
- std::make_pair(vectorOfInts.begin(),
- vectorOfInts.end()));
- /*GwithRange funcGraphWithRange2 = boost::make_function_graph(less_than<int>(),
- std::make_pair(vectorOfInts.begin(),
- vectorOfInts.end()));*/
+ // Create vertices and function_graph
+ unsigned int tempArray[5] = {5, 4, 9, 2, 7};
+ std::vector<unsigned int> vectorOfInts(tempArray, tempArray + 5);
+ FuncGraph graph(std::less<int>(),
+ std::make_pair(vectorOfInts.begin(), vectorOfInts.end()));
+ ////////
+ // Create iterators
+ iterator_range graphDataRange = vertices(graph);
+ FuncGraph::in_edge_iterator graphIterator(std::less<int>(),
+ ++vectorOfInts.begin(),
+ vectorOfInts.begin(),
+ vectorOfInts.end());
 
-
+ ////////
+ // Check iteration
+ print_edge((*graphIterator));
+ ++graphIterator;
+ print_edge((*graphIterator));
+ ++graphIterator;
+ print_edge((*graphIterator));
 
     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