labeled_graph_traits.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Copyright (C) 2009 Andrew Sutton
  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. #ifndef BOOST_GRAPH_LABELED_GRAPH_TRAITS_HPP
  6. #define BOOST_GRAPH_LABELED_GRAPH_TRAITS_HPP
  7. #include <boost/graph/graph_mutability_traits.hpp>
  8. namespace boost
  9. {
  10. // Extend the graph mutability traits (and metafunctions) to include options
  11. // for labeled graphs.
  12. // NOTE: the label_vertex tag denotes the fact that you can basically assign
  13. // arbitrary labels to vertices without modifying the actual graph.
  14. // TODO: We might also overlay the uniqueness/multiplicity of labels in this
  15. // hierarchy also. For now, we just assumed that labels are unique.
  16. struct label_vertex_tag
  17. {
  18. };
  19. struct labeled_add_vertex_tag : virtual label_vertex_tag
  20. {
  21. };
  22. struct labeled_add_vertex_property_tag : virtual labeled_add_vertex_tag
  23. {
  24. };
  25. struct labeled_remove_vertex_tag
  26. {
  27. };
  28. struct labeled_add_edge_tag : virtual label_vertex_tag
  29. {
  30. };
  31. struct labeled_add_edge_property_tag : virtual labeled_add_edge_tag
  32. {
  33. };
  34. struct labeled_remove_edge_tag
  35. {
  36. };
  37. struct labeled_mutable_vertex_graph_tag : virtual labeled_add_vertex_tag,
  38. virtual labeled_remove_vertex_tag
  39. {
  40. };
  41. struct labeled_mutable_vertex_property_graph_tag
  42. : virtual labeled_add_vertex_property_tag,
  43. virtual labeled_remove_vertex_tag
  44. {
  45. };
  46. struct labeled_mutable_edge_graph_tag : virtual labeled_add_edge_tag,
  47. virtual labeled_remove_edge_tag
  48. {
  49. };
  50. struct labeled_mutable_edge_property_graph_tag
  51. : virtual labeled_add_edge_property_tag,
  52. virtual labeled_remove_edge_tag
  53. {
  54. };
  55. struct labeled_graph_tag : virtual label_vertex_tag
  56. {
  57. };
  58. struct labeled_mutable_graph_tag : virtual labeled_mutable_vertex_graph_tag,
  59. virtual labeled_mutable_edge_graph_tag
  60. {
  61. };
  62. struct labeled_mutable_property_graph_tag
  63. : virtual labeled_mutable_vertex_property_graph_tag,
  64. virtual labeled_mutable_edge_property_graph_tag
  65. {
  66. };
  67. struct labeled_add_only_property_graph_tag
  68. : virtual labeled_add_vertex_property_tag,
  69. virtual labeled_mutable_edge_property_graph_tag
  70. {
  71. };
  72. // Metafunctions
  73. template < typename Graph >
  74. struct graph_has_add_vertex_by_label
  75. : mpl::bool_<
  76. is_convertible< typename graph_mutability_traits< Graph >::category,
  77. labeled_add_vertex_tag >::value >
  78. {
  79. };
  80. template < typename Graph >
  81. struct graph_has_add_vertex_by_label_with_property
  82. : mpl::bool_<
  83. is_convertible< typename graph_mutability_traits< Graph >::category,
  84. labeled_add_vertex_property_tag >::value >
  85. {
  86. };
  87. template < typename Graph >
  88. struct graph_has_remove_vertex_by_label
  89. : mpl::bool_<
  90. is_convertible< typename graph_mutability_traits< Graph >::category,
  91. labeled_remove_vertex_tag >::value >
  92. {
  93. };
  94. template < typename Graph >
  95. struct graph_has_add_edge_by_label
  96. : mpl::bool_<
  97. is_convertible< typename graph_mutability_traits< Graph >::category,
  98. labeled_add_edge_tag >::value >
  99. {
  100. };
  101. template < typename Graph >
  102. struct graph_has_add_edge_by_label_with_property
  103. : mpl::bool_<
  104. is_convertible< typename graph_mutability_traits< Graph >::category,
  105. labeled_add_edge_property_tag >::value >
  106. {
  107. };
  108. template < typename Graph >
  109. struct graph_has_remove_edge_by_label
  110. : mpl::bool_<
  111. is_convertible< typename graph_mutability_traits< Graph >::category,
  112. labeled_remove_edge_tag >::value >
  113. {
  114. };
  115. template < typename Graph >
  116. struct is_labeled_mutable_vertex_graph
  117. : mpl::and_< graph_has_add_vertex_by_label< Graph >,
  118. graph_has_remove_vertex_by_label< Graph > >
  119. {
  120. };
  121. template < typename Graph >
  122. struct is_labeled_mutable_vertex_property_graph
  123. : mpl::and_< graph_has_add_vertex_by_label< Graph >,
  124. graph_has_remove_vertex_by_label< Graph > >
  125. {
  126. };
  127. template < typename Graph >
  128. struct is_labeled_mutable_edge_graph
  129. : mpl::and_< graph_has_add_edge_by_label< Graph >,
  130. graph_has_remove_edge_by_label< Graph > >
  131. {
  132. };
  133. template < typename Graph >
  134. struct is_labeled_mutable_edge_property_graph
  135. : mpl::and_< graph_has_add_edge_by_label< Graph >,
  136. graph_has_remove_edge_by_label< Graph > >
  137. {
  138. };
  139. template < typename Graph >
  140. struct is_labeled_mutable_graph
  141. : mpl::and_< is_labeled_mutable_vertex_graph< Graph >,
  142. is_labeled_mutable_edge_graph< Graph > >
  143. {
  144. };
  145. template < typename Graph >
  146. struct is_labeled_mutable_property_graph
  147. : mpl::and_< is_labeled_mutable_vertex_property_graph< Graph >,
  148. is_labeled_mutable_edge_property_graph< Graph > >
  149. {
  150. };
  151. template < typename Graph >
  152. struct is_labeled_add_only_property_graph
  153. : mpl::bool_<
  154. is_convertible< typename graph_mutability_traits< Graph >::category,
  155. labeled_add_only_property_graph_tag >::value >
  156. {
  157. };
  158. template < typename Graph >
  159. struct is_labeled_graph
  160. : mpl::bool_<
  161. is_convertible< typename graph_mutability_traits< Graph >::category,
  162. label_vertex_tag >::value >
  163. {
  164. };
  165. template < typename > struct graph_mutability_traits;
  166. namespace graph_detail
  167. {
  168. // The determine mutability metafunction computes a labeled mutability tag
  169. // based on the mutability of the given graph type. This is used by the
  170. // graph_mutability_traits specialization below.
  171. template < typename Graph > struct determine_mutability
  172. {
  173. typedef typename mpl::if_< is_add_only_property_graph< Graph >,
  174. labeled_add_only_property_graph_tag,
  175. typename mpl::if_< is_mutable_property_graph< Graph >,
  176. labeled_mutable_property_graph_tag,
  177. typename mpl::if_< is_mutable_graph< Graph >,
  178. labeled_mutable_graph_tag,
  179. typename mpl::if_< is_mutable_edge_graph< Graph >,
  180. labeled_graph_tag,
  181. typename graph_mutability_traits< Graph >::category >::
  182. type >::type >::type >::type type;
  183. };
  184. } // namespace graph_detail
  185. #define LABELED_GRAPH_PARAMS typename G, typename L, typename S
  186. #define LABELED_GRAPH labeled_graph< G, L, S >
  187. // Specialize mutability traits for the labeled graph.
  188. // This specialization depends on the mutability of the underlying graph type.
  189. // If the underlying graph is fully mutable, this is also fully mutable.
  190. // Otherwise, it's different.
  191. template < LABELED_GRAPH_PARAMS >
  192. struct graph_mutability_traits< LABELED_GRAPH >
  193. {
  194. typedef typename graph_detail::determine_mutability<
  195. typename LABELED_GRAPH::graph_type >::type category;
  196. };
  197. #undef LABELED_GRAPH_PARAMS
  198. #undef LABELED_GRAPH
  199. } // namespace boost
  200. #endif