1 // Copyright (C) 2009 Andrew Sutton
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)
7 #ifndef BOOST_GRAPH_LABELED_GRAPH_TRAITS_HPP
8 #define BOOST_GRAPH_LABELED_GRAPH_TRAITS_HPP
10 #include <boost/graph/graph_mutability_traits.hpp>
14 // Extend the graph mutability traits (and metafunctions) to include options
15 // for labeled graphs.
17 // NOTE: the label_vertex tag denotes the fact that you can basically assign
18 // arbitrary labels to vertices without modifying the actual graph.
20 // TODO: We might also overlay the uniqueness/multiplicity of labels in this
21 // hierarchy also. For now, we just assumed that labels are unique.
23 struct label_vertex_tag { };
24 struct labeled_add_vertex_tag : virtual label_vertex_tag { };
25 struct labeled_add_vertex_property_tag : virtual labeled_add_vertex_tag { };
26 struct labeled_remove_vertex_tag { };
27 struct labeled_add_edge_tag : virtual label_vertex_tag { };
28 struct labeled_add_edge_property_tag : virtual labeled_add_edge_tag{ };
29 struct labeled_remove_edge_tag { };
31 struct labeled_mutable_vertex_graph_tag
32 : virtual labeled_add_vertex_tag, virtual labeled_remove_vertex_tag
34 struct labeled_mutable_vertex_property_graph_tag
35 : virtual labeled_add_vertex_property_tag, virtual labeled_remove_vertex_tag
37 struct labeled_mutable_edge_graph_tag
38 : virtual labeled_add_edge_tag, virtual labeled_remove_edge_tag
40 struct labeled_mutable_edge_property_graph_tag
41 : virtual labeled_add_edge_property_tag, virtual labeled_remove_edge_tag
44 struct labeled_graph_tag
45 : virtual label_vertex_tag
47 struct labeled_mutable_graph_tag
48 : virtual labeled_mutable_vertex_graph_tag
49 , virtual labeled_mutable_edge_graph_tag
51 struct labeled_mutable_property_graph_tag
52 : virtual labeled_mutable_vertex_property_graph_tag
53 , virtual labeled_mutable_edge_property_graph_tag
55 struct labeled_add_only_property_graph_tag
56 : virtual labeled_add_vertex_property_tag
57 , virtual labeled_mutable_edge_property_graph_tag
62 template <typename Graph>
63 struct graph_has_add_vertex_by_label
66 typename graph_mutability_traits<Graph>::category,
67 labeled_add_vertex_tag
72 template <typename Graph>
73 struct graph_has_add_vertex_by_label_with_property
76 typename graph_mutability_traits<Graph>::category,
77 labeled_add_vertex_property_tag
82 template <typename Graph>
83 struct graph_has_remove_vertex_by_label
86 typename graph_mutability_traits<Graph>::category,
87 labeled_remove_vertex_tag
92 template <typename Graph>
93 struct graph_has_add_edge_by_label
96 typename graph_mutability_traits<Graph>::category,
102 template <typename Graph>
103 struct graph_has_add_edge_by_label_with_property
106 typename graph_mutability_traits<Graph>::category,
107 labeled_add_edge_property_tag
112 template <typename Graph>
113 struct graph_has_remove_edge_by_label
116 typename graph_mutability_traits<Graph>::category,
117 labeled_remove_edge_tag
122 template <typename Graph>
123 struct is_labeled_mutable_vertex_graph
125 graph_has_add_vertex_by_label<Graph>,
126 graph_has_remove_vertex_by_label<Graph>
130 template <typename Graph>
131 struct is_labeled_mutable_vertex_property_graph
133 graph_has_add_vertex_by_label<Graph>,
134 graph_has_remove_vertex_by_label<Graph>
138 template <typename Graph>
139 struct is_labeled_mutable_edge_graph
141 graph_has_add_edge_by_label<Graph>,
142 graph_has_remove_edge_by_label<Graph>
146 template <typename Graph>
147 struct is_labeled_mutable_edge_property_graph
149 graph_has_add_edge_by_label<Graph>,
150 graph_has_remove_edge_by_label<Graph>
154 template <typename Graph>
155 struct is_labeled_mutable_graph
157 is_labeled_mutable_vertex_graph<Graph>,
158 is_labeled_mutable_edge_graph<Graph>
162 template <typename Graph>
163 struct is_labeled_mutable_property_graph
165 is_labeled_mutable_vertex_property_graph<Graph>,
166 is_labeled_mutable_edge_property_graph<Graph>
170 template <typename Graph>
171 struct is_labeled_add_only_property_graph
174 typename graph_mutability_traits<Graph>::category,
175 labeled_add_only_property_graph_tag
180 template <typename Graph>
181 struct is_labeled_graph
184 typename graph_mutability_traits<Graph>::category,
190 template <typename> struct graph_mutability_traits;
192 namespace graph_detail {
193 // The determine mutability metafunction computes a labeled mutability tag
194 // based on the mutability of the given graph type. This is used by the
195 // graph_mutability_traits specialization below.
196 template <typename Graph>
197 struct determine_mutability {
198 typedef typename mpl::if_<
199 is_add_only_property_graph<Graph>,
200 labeled_add_only_property_graph_tag,
202 is_mutable_property_graph<Graph>,
203 labeled_mutable_property_graph_tag,
205 is_mutable_graph<Graph>,
206 labeled_mutable_graph_tag,
208 is_mutable_edge_graph<Graph>,
210 typename graph_mutability_traits<Graph>::category
216 } // namespace graph_detail
218 #define LABELED_GRAPH_PARAMS typename G, typename L, typename S
219 #define LABELED_GRAPH labeled_graph<G,L,S>
221 // Specialize mutability traits for the labeled graph.
222 // This specialization depends on the mutability of the underlying graph type.
223 // If the underlying graph is fully mutable, this is also fully mutable.
224 // Otherwise, it's different.
225 template <LABELED_GRAPH_PARAMS>
226 struct graph_mutability_traits< LABELED_GRAPH > {
227 typedef typename graph_detail::determine_mutability<
228 typename LABELED_GRAPH::graph_type
232 #undef LABELED_GRAPH_PARAMS