graph_mutability_traits.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // Copyright (C) 2009 Andrew Sutton
  2. //
  3. // Use, modification and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GRAPH_MUTABILITY_TRAITS_HPP
  7. #define BOOST_GRAPH_MUTABILITY_TRAITS_HPP
  8. #include <boost/config.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/mpl/and.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. namespace boost {
  14. // The mutabiltiy categories classify graphs by their mutating operations
  15. // on the edge and vertex sets. This is a substantially more refined
  16. // categorization than the MutableGraph and MutablePropertyGraph denote.
  17. // Currently, this framework is only used in the graph tests to help
  18. // dispatch test to the correct places. However, there are probably some
  19. // constructive or destructive algorithms (i.e., graph generators) that
  20. // may use these to describe requirements on graph inputs.
  21. struct add_vertex_tag { };
  22. struct add_vertex_property_tag : virtual add_vertex_tag { };
  23. struct add_edge_tag { };
  24. struct add_edge_property_tag : virtual add_edge_tag { };
  25. struct remove_vertex_tag { };
  26. struct remove_edge_tag { };
  27. struct mutable_vertex_graph_tag
  28. : virtual add_vertex_tag, virtual remove_vertex_tag
  29. { };
  30. struct mutable_vertex_property_graph_tag
  31. : virtual add_vertex_property_tag, virtual remove_vertex_tag
  32. { };
  33. struct mutable_edge_graph_tag
  34. : virtual add_edge_tag, virtual remove_edge_tag
  35. { };
  36. struct mutable_edge_property_graph_tag
  37. : virtual add_edge_property_tag, virtual remove_edge_tag
  38. { };
  39. struct mutable_graph_tag
  40. : virtual mutable_vertex_graph_tag
  41. , virtual mutable_edge_graph_tag
  42. { };
  43. struct mutable_property_graph_tag
  44. : virtual mutable_vertex_property_graph_tag
  45. , virtual mutable_edge_property_graph_tag
  46. { };
  47. // Some graphs just don't like to be torn down. Note this only restricts
  48. // teardown to the set of vertices, not the vertex set.
  49. // TODO: Find a better name for this tag.
  50. struct add_only_property_graph_tag
  51. : virtual add_vertex_property_tag
  52. , virtual mutable_edge_property_graph_tag
  53. { };
  54. /**
  55. * The graph_mutability_traits provide methods for determining the
  56. * interfaces supported by graph classes for adding and removing vertices
  57. * and edges.
  58. */
  59. template <typename Graph>
  60. struct graph_mutability_traits {
  61. typedef typename Graph::mutability_category category;
  62. };
  63. template <typename Graph>
  64. struct graph_has_add_vertex
  65. : mpl::bool_<
  66. is_convertible<
  67. typename graph_mutability_traits<Graph>::category,
  68. add_vertex_tag
  69. >::value
  70. >
  71. { };
  72. template <typename Graph>
  73. struct graph_has_add_vertex_with_property
  74. : mpl::bool_<
  75. is_convertible<
  76. typename graph_mutability_traits<Graph>::category,
  77. add_vertex_property_tag
  78. >::value
  79. >
  80. { };
  81. template <typename Graph>
  82. struct graph_has_remove_vertex
  83. : mpl::bool_<
  84. is_convertible<
  85. typename graph_mutability_traits<Graph>::category,
  86. remove_vertex_tag
  87. >::value
  88. >
  89. { };
  90. template <typename Graph>
  91. struct graph_has_add_edge
  92. : mpl::bool_<
  93. is_convertible<
  94. typename graph_mutability_traits<Graph>::category,
  95. add_edge_tag
  96. >::value
  97. >
  98. { };
  99. template <typename Graph>
  100. struct graph_has_add_edge_with_property
  101. : mpl::bool_<
  102. is_convertible<
  103. typename graph_mutability_traits<Graph>::category,
  104. add_edge_property_tag
  105. >::value
  106. >
  107. { };
  108. template <typename Graph>
  109. struct graph_has_remove_edge
  110. : mpl::bool_<
  111. is_convertible<
  112. typename graph_mutability_traits<Graph>::category,
  113. remove_edge_tag
  114. >::value
  115. >
  116. { };
  117. template <typename Graph>
  118. struct is_mutable_vertex_graph
  119. : mpl::and_<
  120. graph_has_add_vertex<Graph>,
  121. graph_has_remove_vertex<Graph>
  122. >
  123. { };
  124. template <typename Graph>
  125. struct is_mutable_vertex_property_graph
  126. : mpl::and_<
  127. graph_has_add_vertex_with_property<Graph>,
  128. graph_has_remove_vertex<Graph>
  129. >
  130. { };
  131. template <typename Graph>
  132. struct is_mutable_edge_graph
  133. : mpl::and_<
  134. graph_has_add_edge<Graph>,
  135. graph_has_remove_edge<Graph>
  136. >
  137. { };
  138. template <typename Graph>
  139. struct is_mutable_edge_property_graph
  140. : mpl::and_<
  141. graph_has_add_edge_with_property<Graph>,
  142. graph_has_remove_edge<Graph>
  143. >
  144. { };
  145. template <typename Graph>
  146. struct is_mutable_graph
  147. : mpl::and_<
  148. is_mutable_vertex_graph<Graph>,
  149. is_mutable_edge_graph<Graph>
  150. >
  151. { };
  152. template <typename Graph>
  153. struct is_mutable_property_graph
  154. : mpl::and_<
  155. is_mutable_vertex_property_graph<Graph>,
  156. is_mutable_edge_property_graph<Graph>
  157. >
  158. { };
  159. template <typename Graph>
  160. struct is_add_only_property_graph
  161. : mpl::bool_<
  162. is_convertible<
  163. typename graph_mutability_traits<Graph>::category,
  164. add_only_property_graph_tag
  165. >::value
  166. >
  167. { };
  168. /** @name Mutability Traits Specializations */
  169. //@{
  170. //@}
  171. } // namespace boost
  172. #endif