// //======================================================================= // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek // // This file is part of the Boost Graph Library // // You should have received a copy of the License Agreement for the // Boost Graph Library along with the software; see the file LICENSE. // If not, contact Office of Research, University of Notre Dame, Notre // Dame, IN 46556. // // Permission to modify the code and to distribute modified code is // granted, provided the text of this NOTICE is retained, a notice that // the code was modified is included with the above COPYRIGHT NOTICE and // with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE // file is distributed with the modified code. // // LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. // By way of example, but not limitation, Licensor MAKES NO // REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY // PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS // OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS // OR OTHER RIGHTS. //======================================================================= // #ifndef BOOST_GRAPH_CONCEPTS_HPP #define BOOST_GRAPH_CONCEPTS_HPP #include #include #include #include #include #include namespace boost { template struct MultiPassInputIteratorConcept { void constraints() { function_requires< InputIteratorConcept >(); } }; template struct GraphConcept { typedef typename graph_traits::vertex_descriptor vertex_descriptor; typedef typename graph_traits::directed_category directed_category; typedef typename graph_traits::edge_parallel_category edge_parallel_category; typedef typename graph_traits::traversal_category traversal_category; void constraints() { function_requires< DefaultConstructibleConcept >(); function_requires< EqualityComparableConcept >(); function_requires< AssignableConcept >(); } G g; }; template struct IncidenceGraphConcept { typedef typename graph_traits::edge_descriptor edge_descriptor; typedef typename graph_traits::out_edge_iterator out_edge_iterator; typedef typename graph_traits::traversal_category traversal_category; void constraints() { function_requires< GraphConcept >(); function_requires< MultiPassInputIteratorConcept >(); function_requires< DefaultConstructibleConcept >(); function_requires< EqualityComparableConcept >(); function_requires< AssignableConcept >(); function_requires< ConvertibleConcept >(); p = out_edges(v, g); n = out_degree(v, g); e = *p.first; u = source(e, g); v = target(e, g); const_constraints(g); } void const_constraints(const G& g) { p = out_edges(v, g); n = out_degree(v, g); e = *p.first; u = source(e, g); v = target(e, g); } std::pair p; typename graph_traits::vertex_descriptor u, v; typename graph_traits::edge_descriptor e; typename graph_traits::degree_size_type n; G g; }; template struct BidirectionalGraphConcept { typedef typename graph_traits::in_edge_iterator in_edge_iterator; typedef typename graph_traits::traversal_category traversal_category; void constraints() { function_requires< IncidenceGraphConcept >(); function_requires< MultiPassInputIteratorConcept >(); function_requires< ConvertibleConcept >(); p = in_edges(v, g); n = in_degree(v, g); e = *p.first; const_constraints(g); } void const_constraints(const G& g) { p = in_edges(v, g); n = in_degree(v, g); e = *p.first; } std::pair p; typename graph_traits::vertex_descriptor v; typename graph_traits::edge_descriptor e; typename graph_traits::degree_size_type n; G g; }; template struct AdjacencyGraphConcept { typedef typename graph_traits::adjacency_iterator adjacency_iterator; typedef typename graph_traits::traversal_category traversal_category; void constraints() { function_requires< GraphConcept >(); function_requires< MultiPassInputIteratorConcept >(); function_requires< ConvertibleConcept >(); p = adjacent_vertices(v, g); v = *p.first; const_constraints(g); } void const_constraints(const G& g) { p = adjacent_vertices(v, g); } std::pair p; typename graph_traits::vertex_descriptor v; G g; }; // dwa 2003/7/11 -- This clearly shouldn't be neccessary, but if // you want to use vector_as_graph, it is! I'm sure the graph // library leaves these out all over the place. Probably a // redesign involving specializing a template with a static // member function is in order :( // // It is needed in order to allow us to write using boost::vertices as // needed for ADL when using vector_as_graph below. #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \ && !BOOST_WORKAROUND(__GNUC__, <= 2) \ && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) # define BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK #endif #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK template typename T::ThereReallyIsNoMemberByThisNameInT vertices(T const&); #endif template struct VertexListGraphConcept { typedef typename graph_traits::vertex_iterator vertex_iterator; typedef typename graph_traits::vertices_size_type vertices_size_type; typedef typename graph_traits::traversal_category traversal_category; void constraints() { function_requires< GraphConcept >(); function_requires< MultiPassInputIteratorConcept >(); function_requires< ConvertibleConcept >(); #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK // dwa 2003/7/11 -- This clearly shouldn't be neccessary, but if // you want to use vector_as_graph, it is! I'm sure the graph // library leaves these out all over the place. Probably a // redesign involving specializing a template with a static // member function is in order :( using boost::vertices; #endif p = vertices(g); v = *p.first; const_constraints(g); } void const_constraints(const G& g) { #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK // dwa 2003/7/11 -- This clearly shouldn't be neccessary, but if // you want to use vector_as_graph, it is! I'm sure the graph // library leaves these out all over the place. Probably a // redesign involving specializing a template with a static // member function is in order :( using boost::vertices; #endif p = vertices(g); v = *p.first; V = num_vertices(g); } std::pair p; typename graph_traits::vertex_descriptor v; G g; vertices_size_type V; }; template struct EdgeListGraphConcept { typedef typename graph_traits::edge_descriptor edge_descriptor; typedef typename graph_traits::edge_iterator edge_iterator; typedef typename graph_traits::edges_size_type edges_size_type; typedef typename graph_traits::traversal_category traversal_category; void constraints() { function_requires< GraphConcept >(); function_requires< MultiPassInputIteratorConcept >(); function_requires< DefaultConstructibleConcept >(); function_requires< EqualityComparableConcept >(); function_requires< AssignableConcept >(); function_requires< ConvertibleConcept >(); p = edges(g); e = *p.first; u = source(e, g); v = target(e, g); const_constraints(g); } void const_constraints(const G& g) { p = edges(g); E = num_edges(g); e = *p.first; u = source(e, g); v = target(e, g); } std::pair p; typename graph_traits::vertex_descriptor u, v; typename graph_traits::edge_descriptor e; edges_size_type E; G g; }; template struct VertexAndEdgeListGraphConcept { void constraints() { function_requires< VertexListGraphConcept >(); function_requires< EdgeListGraphConcept >(); } }; // Where to put the requirement for this constructor? // G g(n_vertices); // Not in mutable graph, then LEDA graph's can't be models of // MutableGraph. template struct EdgeMutableGraphConcept { typedef typename graph_traits::edge_descriptor edge_descriptor; void constraints() { p = add_edge(u, v, g); remove_edge(u, v, g); remove_edge(e, g); clear_vertex(v, g); } G g; edge_descriptor e; std::pair p; typename graph_traits::vertex_descriptor u, v; }; template struct VertexMutableGraphConcept { void constraints() { v = add_vertex(g); remove_vertex(v, g); } G g; typename graph_traits::vertex_descriptor u, v; }; template struct MutableGraphConcept { void constraints() { function_requires< EdgeMutableGraphConcept >(); function_requires< VertexMutableGraphConcept >(); } }; template struct dummy_edge_predicate { bool operator()(const edge_descriptor&) const { return false; } }; template struct MutableIncidenceGraphConcept { void constraints() { function_requires< MutableGraphConcept >(); remove_edge(iter, g); remove_out_edge_if(u, p, g); } G g; typedef typename graph_traits::edge_descriptor edge_descriptor; dummy_edge_predicate p; typename boost::graph_traits::vertex_descriptor u; typename boost::graph_traits::out_edge_iterator iter; }; template struct MutableBidirectionalGraphConcept { void constraints() { function_requires< MutableIncidenceGraphConcept >(); remove_in_edge_if(u, p, g); } G g; typedef typename graph_traits::edge_descriptor edge_descriptor; dummy_edge_predicate p; typename boost::graph_traits::vertex_descriptor u; }; template struct MutableEdgeListGraphConcept { void constraints() { function_requires< EdgeMutableGraphConcept >(); remove_edge_if(p, g); } G g; typedef typename graph_traits::edge_descriptor edge_descriptor; dummy_edge_predicate p; }; template struct VertexMutablePropertyGraphConcept { void constraints() { function_requires< VertexMutableGraphConcept >(); v = add_vertex(vp, g); } G g; typename graph_traits::vertex_descriptor v; typename vertex_property::type vp; }; template struct EdgeMutablePropertyGraphConcept { typedef typename graph_traits::edge_descriptor edge_descriptor; void constraints() { function_requires< EdgeMutableGraphConcept >(); p = add_edge(u, v, ep, g); } G g; std::pair p; typename graph_traits::vertex_descriptor u, v; typename edge_property::type ep; }; template struct AdjacencyMatrixConcept { typedef typename graph_traits::edge_descriptor edge_descriptor; void constraints() { function_requires< GraphConcept >(); p = edge(u, v, g); const_constraints(g); } void const_constraints(const G& g) { p = edge(u, v, g); } typename graph_traits::vertex_descriptor u, v; std::pair p; G g; }; template struct ReadablePropertyGraphConcept { typedef typename property_map::const_type const_Map; void constraints() { function_requires< GraphConcept >(); function_requires< ReadablePropertyMapConcept >(); const_constraints(g); } void const_constraints(const G& g) { const_Map pmap = get(Property(), g); pval = get(Property(), g, x); ignore_unused_variable_warning(pmap); } G g; X x; typename property_traits::value_type pval; }; template struct PropertyGraphConcept { typedef typename property_map::type Map; void constraints() { function_requires< ReadablePropertyGraphConcept >(); function_requires< ReadWritePropertyMapConcept >(); Map pmap = get(Property(), g); pval = get(Property(), g, x); put(Property(), g, x, pval); ignore_unused_variable_warning(pmap); } G g; X x; typename property_traits::value_type pval; }; template struct LvaluePropertyGraphConcept { typedef typename property_map::type Map; typedef typename property_map::const_type const_Map; void constraints() { function_requires< ReadablePropertyGraphConcept >(); function_requires< LvaluePropertyMapConcept >(); pval = get(Property(), g, x); put(Property(), g, x, pval); } G g; X x; typename property_traits::value_type pval; }; // This needs to move out of the graph library template struct BufferConcept { void constraints() { b.push(t); b.pop(); typename B::value_type& v = b.top(); const_constraints(b); ignore_unused_variable_warning(v); } void const_constraints(const B& b) { const typename B::value_type& v = b.top(); n = b.size(); bool e = b.empty(); ignore_unused_variable_warning(v); ignore_unused_variable_warning(e); } typename B::size_type n; typename B::value_type t; B b; }; template struct ColorValueConcept { void constraints() { function_requires< EqualityComparableConcept >(); function_requires< DefaultConstructibleConcept >(); c = color_traits::white(); c = color_traits::gray(); c = color_traits::black(); } C c; }; template struct BasicMatrixConcept { void constraints() { V& elt = A[i][j]; const_constraints(A); ignore_unused_variable_warning(elt); } void const_constraints(const M& A) { const V& elt = A[i][j]; ignore_unused_variable_warning(elt); } M A; I i, j; }; } // namespace boost #endif /* BOOST_GRAPH_CONCEPTS_H */