concepts.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Copyright (C) 2004-2006 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. // Andrew Lumsdaine
  7. //
  8. // Distributed graph concepts and helpers
  9. //
  10. #ifndef BOOST_GRAPH_DISTRIBUTED_CONCEPTS_HPP
  11. #define BOOST_GRAPH_DISTRIBUTED_CONCEPTS_HPP
  12. #ifndef BOOST_GRAPH_USE_MPI
  13. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  14. #endif
  15. #include <boost/version.hpp>
  16. #include <boost/graph/graph_traits.hpp>
  17. #include <boost/graph/graph_concepts.hpp>
  18. #include <boost/concept/assert.hpp>
  19. #if BOOST_VERSION >= 103500
  20. # include <boost/concept/detail/concept_def.hpp>
  21. #endif
  22. namespace boost {
  23. #if BOOST_VERSION >= 103500
  24. namespace concepts {
  25. #endif
  26. #if BOOST_VERSION < 103500
  27. template <class G>
  28. struct DistributedVertexListGraphConcept
  29. {
  30. typedef typename graph_traits<G>::vertex_iterator vertex_iterator;
  31. typedef typename graph_traits<G>::vertices_size_type vertices_size_type;
  32. typedef typename graph_traits<G>::traversal_category
  33. traversal_category;
  34. void constraints() {
  35. BOOST_CONCEPT_ASSERT(( GraphConcept<G> ));
  36. BOOST_CONCEPT_ASSERT(( MultiPassInputIteratorConcept<vertex_iterator> ));
  37. BOOST_CONCEPT_ASSERT(( ConvertibleConcept<traversal_category,
  38. distributed_vertex_list_graph_tag> ));
  39. #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
  40. // dwa 2003/7/11 -- This clearly shouldn't be necessary, but if
  41. // you want to use vector_as_graph, it is! I'm sure the graph
  42. // library leaves these out all over the place. Probably a
  43. // redesign involving specializing a template with a static
  44. // member function is in order :(
  45. using boost::vertices;
  46. #endif
  47. p = vertices(g);
  48. v = *p.first;
  49. const_constraints(g);
  50. }
  51. void const_constraints(const G& cg) {
  52. #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
  53. // dwa 2003/7/11 -- This clearly shouldn't be necessary, but if
  54. // you want to use vector_as_graph, it is! I'm sure the graph
  55. // library leaves these out all over the place. Probably a
  56. // redesign involving specializing a template with a static
  57. // member function is in order :(
  58. using boost::vertices;
  59. #endif
  60. p = vertices(cg);
  61. v = *p.first;
  62. V = num_vertices(cg);
  63. }
  64. std::pair<vertex_iterator,vertex_iterator> p;
  65. typename graph_traits<G>::vertex_descriptor v;
  66. G g;
  67. vertices_size_type V;
  68. };
  69. template <class G>
  70. struct DistributedEdgeListGraphConcept
  71. {
  72. typedef typename graph_traits<G>::edge_descriptor edge_descriptor;
  73. typedef typename graph_traits<G>::edge_iterator edge_iterator;
  74. typedef typename graph_traits<G>::edges_size_type edges_size_type;
  75. typedef typename graph_traits<G>::traversal_category
  76. traversal_category;
  77. void constraints() {
  78. BOOST_CONCEPT_ASSERT(( GraphConcept<G> ));
  79. BOOST_CONCEPT_ASSERT(( MultiPassInputIteratorConcept<edge_iterator> ));
  80. BOOST_CONCEPT_ASSERT(( DefaultConstructibleConcept<edge_descriptor> ));
  81. BOOST_CONCEPT_ASSERT(( EqualityComparableConcept<edge_descriptor> ));
  82. BOOST_CONCEPT_ASSERT(( AssignableConcept<edge_descriptor> ));
  83. BOOST_CONCEPT_ASSERT(( ConvertibleConcept<traversal_category,
  84. distributed_edge_list_graph_tag> ));
  85. p = edges(g);
  86. e = *p.first;
  87. u = source(e, g);
  88. v = target(e, g);
  89. const_constraints(g);
  90. }
  91. void const_constraints(const G& cg) {
  92. p = edges(cg);
  93. E = num_edges(cg);
  94. e = *p.first;
  95. u = source(e, cg);
  96. v = target(e, cg);
  97. }
  98. std::pair<edge_iterator,edge_iterator> p;
  99. typename graph_traits<G>::vertex_descriptor u, v;
  100. typename graph_traits<G>::edge_descriptor e;
  101. edges_size_type E;
  102. G g;
  103. };
  104. #else
  105. BOOST_concept(DistributedVertexListGraph,(G))
  106. : Graph<G>
  107. {
  108. typedef typename graph_traits<G>::vertex_iterator vertex_iterator;
  109. typedef typename graph_traits<G>::vertices_size_type vertices_size_type;
  110. typedef typename graph_traits<G>::traversal_category
  111. traversal_category;
  112. ~DistributedVertexListGraph() {
  113. BOOST_CONCEPT_ASSERT((MultiPassInputIterator<vertex_iterator>));
  114. BOOST_CONCEPT_ASSERT((Convertible<traversal_category,
  115. distributed_vertex_list_graph_tag>));
  116. #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
  117. // dwa 2003/7/11 -- This clearly shouldn't be necessary, but if
  118. // you want to use vector_as_graph, it is! I'm sure the graph
  119. // library leaves these out all over the place. Probably a
  120. // redesign involving specializing a template with a static
  121. // member function is in order :(
  122. using boost::vertices;
  123. #endif
  124. p = vertices(g);
  125. v = *p.first;
  126. const_constraints(g);
  127. }
  128. void const_constraints(const G& cg) {
  129. #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK
  130. // dwa 2003/7/11 -- This clearly shouldn't be necessary, but if
  131. // you want to use vector_as_graph, it is! I'm sure the graph
  132. // library leaves these out all over the place. Probably a
  133. // redesign involving specializing a template with a static
  134. // member function is in order :(
  135. using boost::vertices;
  136. #endif
  137. p = vertices(cg);
  138. v = *p.first;
  139. V = num_vertices(cg);
  140. }
  141. std::pair<vertex_iterator,vertex_iterator> p;
  142. typename graph_traits<G>::vertex_descriptor v;
  143. G g;
  144. vertices_size_type V;
  145. };
  146. BOOST_concept(DistributedEdgeListGraph,(G))
  147. : Graph<G>
  148. {
  149. typedef typename graph_traits<G>::edge_descriptor edge_descriptor;
  150. typedef typename graph_traits<G>::edge_iterator edge_iterator;
  151. typedef typename graph_traits<G>::edges_size_type edges_size_type;
  152. typedef typename graph_traits<G>::traversal_category
  153. traversal_category;
  154. ~DistributedEdgeListGraph() {
  155. BOOST_CONCEPT_ASSERT((MultiPassInputIterator<edge_iterator>));
  156. BOOST_CONCEPT_ASSERT((DefaultConstructible<edge_descriptor>));
  157. BOOST_CONCEPT_ASSERT((EqualityComparable<edge_descriptor>));
  158. BOOST_CONCEPT_ASSERT((Assignable<edge_descriptor>));
  159. BOOST_CONCEPT_ASSERT((Convertible<traversal_category,
  160. distributed_edge_list_graph_tag>));
  161. p = edges(g);
  162. e = *p.first;
  163. u = source(e, g);
  164. v = target(e, g);
  165. const_constraints(g);
  166. }
  167. void const_constraints(const G& cg) {
  168. p = edges(cg);
  169. E = num_edges(cg);
  170. e = *p.first;
  171. u = source(e, cg);
  172. v = target(e, cg);
  173. }
  174. std::pair<edge_iterator,edge_iterator> p;
  175. typename graph_traits<G>::vertex_descriptor u, v;
  176. typename graph_traits<G>::edge_descriptor e;
  177. edges_size_type E;
  178. G g;
  179. };
  180. #endif
  181. #if BOOST_VERSION >= 103500
  182. } // end namespace concepts
  183. using concepts::DistributedVertexListGraphConcept;
  184. using concepts::DistributedEdgeListGraphConcept;
  185. #endif
  186. } // end namespace boost
  187. #if BOOST_VERSION >= 103500
  188. # include <boost/concept/detail/concept_undef.hpp>
  189. #endif
  190. #endif // BOOST_GRAPH_DISTRIBUTED_CONCEPTS_HPP