labeled_graph_traits.hpp 6.8 KB

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