graph_mutability_traits.hpp 4.9 KB

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