graph_mutability_traits.hpp 4.9 KB

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