Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54647 - in sandbox/SOC/2009/function_graph: boost/function_graph libs/test
From: mlopez7_at_[hidden]
Date: 2009-07-04 12:28:25


Author: lopezeant
Date: 2009-07-04 12:28:25 EDT (Sat, 04 Jul 2009)
New Revision: 54647
URL: http://svn.boost.org/trac/boost/changeset/54647

Log:
Changing how edge checking works and made new test for iterators.
Added:
   sandbox/SOC/2009/function_graph/libs/test/test3.cpp
      - copied, changed from r54599, /sandbox/SOC/2009/function_graph/libs/test/test2.cpp
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 101 +++++++++++++++++++--------------------
   sandbox/SOC/2009/function_graph/libs/test/test3.cpp | 66 +++++++++++++++-----------
   2 files changed, 87 insertions(+), 80 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-07-04 12:28:25 EDT (Sat, 04 Jul 2009)
@@ -54,6 +54,44 @@
     vertex_descriptor target_;
 };
 
+
+
+/** @name bind_edge
+ * 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>.
+ */
+
+//@{
+template <typename Result, typename Vertex>
+std::pair<detail::func_graph_edge<Result, Vertex>, bool>
+bind_edge(Result const& r, Vertex u, Vertex 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 r, Vertex u, Vertex v)
+{
+ return std::make_pair(typename detail::func_graph_edge<
+ 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& r, Vertex u, Vertex v)
+{
+ return std::make_pair(detail::func_graph_edge<
+ optional<OptType>, Vertex
+ >(r, u, v),
+ (bool)r);
+}
+
 } // detail namespace
 
 
@@ -67,12 +105,13 @@
 //@{
 template <typename Func>
 struct function_graph_base {
-
     typedef Func function_type;
     typedef typename function_type::first_argument_type vertex_type;
     typedef typename function_type::result_type result_type;
- typedef typename detail::func_graph_edge<result_type,
- vertex_type> edge_type;
+ typedef typename detail::func_graph_edge<
+ result_type,
+ vertex_type
+ > edge_type;
 
     /** Constructors to allow for initialization of edge */
     function_graph_base(function_type const& f)
@@ -165,7 +204,8 @@
         do {
             ++vertex_begin_;
         } while((vertex_begin_ != vertex_end_) &&
- !edge_(*vertex_begin_, *vertex_));
+ !detail::bind_edge(edge_(vertex_begin_, vertex_),
+ vertex_begin_, vertex_).second);
 
         return *this;
     }
@@ -324,10 +364,10 @@
 /** @internal Allow a template function parameter without wrapping it with
  * boost::function.
  */
-template <typename Result, typename Vertex, typename Range>
+/*template <typename Result, typename Vertex, typename Range>
 struct function_graph<Result(Vertex, Vertex), Range>
     : public function_graph<function<Result(Vertex, Vertex)>, Range>
-{ };
+{ };*/
 
 // Specialization of function_graph without range
 template <typename Result, typename Vertex>
@@ -356,11 +396,10 @@
     { }
 };
 
-
-template <typename Result, typename Vertex>
+/*template <typename Result, typename Vertex>
 struct function_graph<Result(Vertex, Vertex), infinite_domain_tag>
     : public function_graph<function<Result(Vertex, Vertex)> >
-{ };
+{ };*/
 
 
 
@@ -498,51 +537,9 @@
 template<typename Result, typename Vertex, typename Range>
 typename FUNC_GRAPH::vertices_size_type
 num_vertices(FUNC_GRAPH const& g)
-{
- return size(g.range_);
-}
-
-
-
-/** @name bind_edge
- * 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>.
- */
-
-//@{
-namespace detail {
-
-template <typename Result, typename Vertex>
-std::pair<detail::func_graph_edge<Result, Vertex>, bool>
-bind_edge(Result const& r, Vertex u, Vertex v)
-{
- return std::make_pair(detail::func_graph_edge<Result, Vertex>(r, u, v),
- true);
-}
+{ return size(g.range_); }
 
-template <typename Vertex>
-std::pair<detail::func_graph_edge<bool, Vertex>, bool>
-bind_edge(bool r, Vertex u, Vertex v)
-{
- return std::make_pair(typename detail::func_graph_edge<
- 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& r, Vertex u, Vertex v)
-{
- return std::make_pair(detail::func_graph_edge<
- optional<OptType>, Vertex
- >(r, u, v),
- (bool)r);
-}
-
-} // detail namespace
 
 template <typename Result, typename Vertex, typename Range>
 std::pair<typename FUNC_GRAPH::edge_descriptor, bool>

Copied: sandbox/SOC/2009/function_graph/libs/test/test3.cpp (from r54599, /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/test3.cpp 2009-07-04 12:28:25 EDT (Sat, 04 Jul 2009)
@@ -11,6 +11,7 @@
 #include <vector>
 #include "function_graph.hpp"
 #include <boost/range.hpp>
+#include <cassert>
 
 // print an edge
 template<typename Result, typename Vertex>
@@ -20,37 +21,46 @@
     std::cout << " Target: " << e.target_ << "\n";
 }
 
-
 int main()
 {
     ////////
- // 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<boolean_function, iterator_range> FuncGraph;
-
- ////////
- // 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);
+ // Data for graph
+ long arr[8] = {56233, 572, -7851, 956242, -2, 893437, 63, 4474443};
+ std::vector<long> numbers(arr, arr + 8);
+
+ ////////
+ // Typedefs
+ typedef std::pair<
+ std::vector<long>::iterator,
+ std::vector<long>::iterator
+ > iterator_range;
+ typedef boost::function<bool(long, long)> boolean_func;
+ typedef boost::function<long(long, long)> weighted_func;
+ typedef boost::function_graph<boolean_func, iterator_range> boolean_graph;
+ typedef boost::function_graph<weighted_func, iterator_range> weighted_graph;
+
+ ////////
+ // Create function graphs
+ boolean_graph booleanGraph(std::less<long>(),
+ std::make_pair(numbers.begin(), numbers.end()));
+ weighted_graph weightedGraph(std::minus<long>(),
+ std::make_pair(numbers.begin(), numbers.end()));
+
+ ////////
+ // Check vertices(g)
+ iterator_range correctRange = std::make_pair(numbers.begin(),
+ numbers.end());
+ assert(vertices(booleanGraph) == correctRange);
+ assert(vertices(weightedGraph) == correctRange);
+
+ ////////
+ // Check num_vertices
+ std::vector<long>::size_type numVertices = numbers.size();
+ assert(num_vertices(booleanGraph) == numVertices);
+ assert(num_vertices(weightedGraph) == numVertices);
+
+ ////////
+ // Check in edges
 
     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