annotate DEPENDENCIES/generic/include/boost/graph/named_graph.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Copyright (C) 2007 Douglas Gregor
Chris@16 2
Chris@16 3 // Use, modification and distribution is subject to the Boost Software
Chris@16 4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 // Provides support for named vertices in graphs, allowing one to more
Chris@16 8 // easily associate unique external names (URLs, city names, employee
Chris@16 9 // ID numbers, etc.) with the vertices of a graph.
Chris@16 10 #ifndef BOOST_GRAPH_NAMED_GRAPH_HPP
Chris@16 11 #define BOOST_GRAPH_NAMED_GRAPH_HPP
Chris@16 12
Chris@16 13 #include <boost/config.hpp>
Chris@16 14 #include <boost/static_assert.hpp>
Chris@16 15 #include <boost/functional/hash.hpp>
Chris@16 16 #include <boost/graph/graph_traits.hpp>
Chris@16 17 #include <boost/graph/properties.hpp>
Chris@16 18 #include <boost/multi_index/hashed_index.hpp>
Chris@16 19 #include <boost/multi_index/member.hpp>
Chris@16 20 #include <boost/multi_index_container.hpp>
Chris@16 21 #include <boost/optional.hpp>
Chris@16 22 #include <boost/pending/property.hpp> // for boost::lookup_one_property
Chris@16 23 #include <boost/pending/container_traits.hpp>
Chris@16 24 #include <boost/throw_exception.hpp>
Chris@16 25 #include <boost/tuple/tuple.hpp> // for boost::make_tuple
Chris@16 26 #include <boost/type_traits/is_same.hpp>
Chris@16 27 #include <boost/type_traits/is_base_of.hpp>
Chris@16 28 #include <boost/type_traits/remove_cv.hpp>
Chris@16 29 #include <boost/type_traits/remove_reference.hpp>
Chris@16 30 #include <boost/utility/enable_if.hpp>
Chris@16 31 #include <functional> // for std::equal_to
Chris@16 32 #include <stdexcept> // for std::runtime_error
Chris@16 33 #include <utility> // for std::pair
Chris@16 34
Chris@16 35 namespace boost { namespace graph {
Chris@16 36
Chris@16 37 /*******************************************************************
Chris@16 38 * User-customized traits *
Chris@16 39 *******************************************************************/
Chris@16 40
Chris@16 41 /**
Chris@16 42 * @brief Trait used to extract the internal vertex name from a vertex
Chris@16 43 * property.
Chris@16 44 *
Chris@16 45 * To enable the use of internal vertex names in a graph type,
Chris@16 46 * specialize the @c internal_vertex_name trait for your graph
Chris@16 47 * property (e.g., @c a City class, which stores information about the
Chris@16 48 * vertices in a road map).
Chris@16 49 */
Chris@16 50 template<typename VertexProperty>
Chris@16 51 struct internal_vertex_name
Chris@16 52 {
Chris@16 53 /**
Chris@16 54 * The @c type field provides a function object that extracts a key
Chris@16 55 * from the @c VertexProperty. The function object type must have a
Chris@16 56 * nested @c result_type that provides the type of the key. For
Chris@16 57 * more information, see the @c KeyExtractor concept in the
Chris@16 58 * Boost.MultiIndex documentation: @c type must either be @c void
Chris@16 59 * (if @c VertexProperty does not have an internal vertex name) or
Chris@16 60 * a model of @c KeyExtractor.
Chris@16 61 */
Chris@16 62 typedef void type;
Chris@16 63 };
Chris@16 64
Chris@16 65 /**
Chris@16 66 * Extract the internal vertex name from a @c property structure by
Chris@16 67 * looking at its base.
Chris@16 68 */
Chris@16 69 template<typename Tag, typename T, typename Base>
Chris@16 70 struct internal_vertex_name<property<Tag, T, Base> >
Chris@16 71 : internal_vertex_name<Base> { };
Chris@16 72
Chris@16 73 /**
Chris@16 74 * Construct an instance of @c VertexProperty directly from its
Chris@16 75 * name. This function object should be used within the @c
Chris@16 76 * internal_vertex_constructor trait.
Chris@16 77 */
Chris@16 78 template<typename VertexProperty>
Chris@16 79 struct vertex_from_name
Chris@16 80 {
Chris@16 81 private:
Chris@16 82 typedef typename internal_vertex_name<VertexProperty>::type extract_name_type;
Chris@16 83
Chris@16 84 typedef typename remove_cv<
Chris@16 85 typename remove_reference<
Chris@16 86 typename extract_name_type::result_type>::type>::type
Chris@16 87 vertex_name_type;
Chris@16 88
Chris@16 89 public:
Chris@16 90 typedef vertex_name_type argument_type;
Chris@16 91 typedef VertexProperty result_type;
Chris@16 92
Chris@16 93 VertexProperty operator()(const vertex_name_type& name)
Chris@16 94 {
Chris@16 95 return VertexProperty(name);
Chris@16 96 }
Chris@16 97 };
Chris@16 98
Chris@16 99 /**
Chris@16 100 * Throw an exception whenever one tries to construct a @c
Chris@16 101 * VertexProperty instance from its name.
Chris@16 102 */
Chris@16 103 template<typename VertexProperty>
Chris@16 104 struct cannot_add_vertex
Chris@16 105 {
Chris@16 106 private:
Chris@16 107 typedef typename internal_vertex_name<VertexProperty>::type extract_name_type;
Chris@16 108
Chris@16 109 typedef typename remove_cv<
Chris@16 110 typename remove_reference<
Chris@16 111 typename extract_name_type::result_type>::type>::type
Chris@16 112 vertex_name_type;
Chris@16 113
Chris@16 114 public:
Chris@16 115 typedef vertex_name_type argument_type;
Chris@16 116 typedef VertexProperty result_type;
Chris@16 117
Chris@16 118 VertexProperty operator()(const vertex_name_type&)
Chris@16 119 {
Chris@16 120 boost::throw_exception(std::runtime_error("add_vertex: "
Chris@16 121 "unable to create a vertex from its name"));
Chris@16 122 }
Chris@16 123 };
Chris@16 124
Chris@16 125 /**
Chris@16 126 * @brief Trait used to construct an instance of a @c VertexProperty,
Chris@16 127 * which is a class type that stores the properties associated with a
Chris@16 128 * vertex in a graph, from just the name of that vertex property. This
Chris@16 129 * operation is used when an operation is required to map from a
Chris@16 130 * vertex name to a vertex descriptor (e.g., to add an edge outgoing
Chris@16 131 * from that vertex), but no vertex by the name exists. The function
Chris@16 132 * object provided by this trait will be used to add new vertices
Chris@16 133 * based only on their names. Since this cannot be done for arbitrary
Chris@16 134 * types, the default behavior is to throw an exception when this
Chris@16 135 * routine is called, which requires that all named vertices be added
Chris@16 136 * before adding any edges by name.
Chris@16 137 */
Chris@16 138 template<typename VertexProperty>
Chris@16 139 struct internal_vertex_constructor
Chris@16 140 {
Chris@16 141 /**
Chris@16 142 * The @c type field provides a function object that constructs a
Chris@16 143 * new instance of @c VertexProperty from the name of the vertex (as
Chris@16 144 * determined by @c internal_vertex_name). The function object shall
Chris@16 145 * accept a vertex name and return a @c VertexProperty. Predefined
Chris@16 146 * options include:
Chris@16 147 *
Chris@16 148 * @c vertex_from_name<VertexProperty>: construct an instance of
Chris@16 149 * @c VertexProperty directly from the name.
Chris@16 150 *
Chris@16 151 * @c cannot_add_vertex<VertexProperty>: the default value, which
Chris@16 152 * throws an @c std::runtime_error if one attempts to add a vertex
Chris@16 153 * given just the name.
Chris@16 154 */
Chris@16 155 typedef cannot_add_vertex<VertexProperty> type;
Chris@16 156 };
Chris@16 157
Chris@16 158 /**
Chris@16 159 * Extract the internal vertex constructor from a @c property structure by
Chris@16 160 * looking at its base.
Chris@16 161 */
Chris@16 162 template<typename Tag, typename T, typename Base>
Chris@16 163 struct internal_vertex_constructor<property<Tag, T, Base> >
Chris@16 164 : internal_vertex_constructor<Base> { };
Chris@16 165
Chris@16 166 /*******************************************************************
Chris@16 167 * Named graph mixin *
Chris@16 168 *******************************************************************/
Chris@16 169
Chris@16 170 /**
Chris@16 171 * named_graph is a mixin that provides names for the vertices of a
Chris@16 172 * graph, including a mapping from names to vertices. Graph types that
Chris@16 173 * may or may not be have vertex names (depending on the properties
Chris@16 174 * supplied by the user) should use maybe_named_graph.
Chris@16 175 *
Chris@16 176 * Template parameters:
Chris@16 177 *
Chris@16 178 * Graph: the graph type that derives from named_graph
Chris@16 179 *
Chris@16 180 * Vertex: the type of a vertex descriptor in Graph. Note: we cannot
Chris@16 181 * use graph_traits here, because the Graph is not yet defined.
Chris@16 182 *
Chris@16 183 * VertexProperty: the type stored with each vertex in the Graph.
Chris@16 184 */
Chris@16 185 template<typename Graph, typename Vertex, typename VertexProperty>
Chris@16 186 class named_graph
Chris@16 187 {
Chris@16 188 public:
Chris@16 189 /// The type of the function object that extracts names from vertex
Chris@16 190 /// properties.
Chris@16 191 typedef typename internal_vertex_name<VertexProperty>::type extract_name_type;
Chris@16 192 /// The type of the "bundled" property, from which the name can be
Chris@16 193 /// extracted.
Chris@16 194 typedef typename lookup_one_property<VertexProperty, vertex_bundle_t>::type
Chris@16 195 bundled_vertex_property_type;
Chris@16 196
Chris@16 197 /// The type of the function object that generates vertex properties
Chris@16 198 /// from names, for the implicit addition of vertices.
Chris@16 199 typedef typename internal_vertex_constructor<VertexProperty>::type
Chris@16 200 vertex_constructor_type;
Chris@16 201
Chris@16 202 /// The type used to name vertices in the graph
Chris@16 203 typedef typename remove_cv<
Chris@16 204 typename remove_reference<
Chris@16 205 typename extract_name_type::result_type>::type>::type
Chris@16 206 vertex_name_type;
Chris@16 207
Chris@16 208 /// The type of vertex descriptors in the graph
Chris@16 209 typedef Vertex vertex_descriptor;
Chris@16 210
Chris@16 211 private:
Chris@16 212 /// Key extractor for use with the multi_index_container
Chris@16 213 struct extract_name_from_vertex
Chris@16 214 {
Chris@16 215 typedef vertex_name_type result_type;
Chris@16 216
Chris@16 217 extract_name_from_vertex(Graph& graph, const extract_name_type& extract)
Chris@16 218 : graph(graph), extract(extract) { }
Chris@16 219
Chris@16 220 const result_type& operator()(Vertex vertex) const
Chris@16 221 {
Chris@16 222 return extract(graph[vertex]);
Chris@16 223 }
Chris@16 224
Chris@16 225 Graph& graph;
Chris@16 226 extract_name_type extract;
Chris@16 227 };
Chris@16 228
Chris@16 229 public:
Chris@16 230 /// The type that maps names to vertices
Chris@16 231 typedef multi_index::multi_index_container<
Chris@16 232 Vertex,
Chris@16 233 multi_index::indexed_by<
Chris@16 234 multi_index::hashed_unique<multi_index::tag<vertex_name_t>,
Chris@16 235 extract_name_from_vertex> >
Chris@16 236 > named_vertices_type;
Chris@16 237
Chris@16 238 /// The set of vertices, indexed by name
Chris@16 239 typedef typename named_vertices_type::template index<vertex_name_t>::type
Chris@16 240 vertices_by_name_type;
Chris@16 241
Chris@16 242 /// Construct an instance of the named graph mixin, using the given
Chris@16 243 /// function object to extract a name from the bundled property
Chris@16 244 /// associated with a vertex.
Chris@16 245 named_graph(const extract_name_type& extract = extract_name_type(),
Chris@16 246 const vertex_constructor_type& vertex_constructor
Chris@16 247 = vertex_constructor_type());
Chris@16 248
Chris@16 249 /// Notify the named_graph that we have added the given vertex. The
Chris@16 250 /// name of the vertex will be added to the mapping.
Chris@16 251 void added_vertex(Vertex vertex);
Chris@16 252
Chris@16 253 /// Notify the named_graph that we are removing the given
Chris@16 254 /// vertex. The name of the vertex will be removed from the mapping.
Chris@16 255 template <typename VertexIterStability>
Chris@16 256 void removing_vertex(Vertex vertex, VertexIterStability);
Chris@16 257
Chris@16 258 /// Notify the named_graph that we are clearing the graph.
Chris@16 259 /// This will clear out all of the name->vertex mappings
Chris@16 260 void clearing_graph();
Chris@16 261
Chris@16 262 /// Retrieve the derived instance
Chris@16 263 Graph& derived() { return static_cast<Graph&>(*this); }
Chris@16 264 const Graph& derived() const { return static_cast<const Graph&>(*this); }
Chris@16 265
Chris@16 266 /// Extract the name from a vertex property instance
Chris@16 267 typename extract_name_type::result_type
Chris@16 268 extract_name(const bundled_vertex_property_type& property);
Chris@16 269
Chris@16 270 /// Search for a vertex that has the given property (based on its
Chris@16 271 /// name)
Chris@16 272 optional<vertex_descriptor>
Chris@16 273 vertex_by_property(const bundled_vertex_property_type& property);
Chris@16 274
Chris@16 275 /// Mapping from names to vertices
Chris@16 276 named_vertices_type named_vertices;
Chris@16 277
Chris@16 278 /// Constructs a vertex from the name of that vertex
Chris@16 279 vertex_constructor_type vertex_constructor;
Chris@16 280 };
Chris@16 281
Chris@16 282 /// Helper macro containing the template parameters of named_graph
Chris@16 283 #define BGL_NAMED_GRAPH_PARAMS \
Chris@16 284 typename Graph, typename Vertex, typename VertexProperty
Chris@16 285 /// Helper macro containing the named_graph<...> instantiation
Chris@16 286 #define BGL_NAMED_GRAPH \
Chris@16 287 named_graph<Graph, Vertex, VertexProperty>
Chris@16 288
Chris@16 289 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 290 BGL_NAMED_GRAPH::named_graph(const extract_name_type& extract,
Chris@16 291 const vertex_constructor_type& vertex_constructor)
Chris@16 292 : named_vertices(
Chris@16 293 typename named_vertices_type::ctor_args_list(
Chris@16 294 boost::make_tuple(
Chris@16 295 boost::make_tuple(
Chris@16 296 0, // initial number of buckets
Chris@16 297 extract_name_from_vertex(derived(), extract),
Chris@16 298 boost::hash<vertex_name_type>(),
Chris@16 299 std::equal_to<vertex_name_type>())))),
Chris@16 300 vertex_constructor(vertex_constructor)
Chris@16 301 {
Chris@16 302 }
Chris@16 303
Chris@16 304 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 305 inline void BGL_NAMED_GRAPH::added_vertex(Vertex vertex)
Chris@16 306 {
Chris@16 307 named_vertices.insert(vertex);
Chris@16 308 }
Chris@16 309
Chris@16 310 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 311 template<typename VertexIterStability>
Chris@16 312 inline void BGL_NAMED_GRAPH::removing_vertex(Vertex vertex, VertexIterStability)
Chris@16 313 {
Chris@16 314 BOOST_STATIC_ASSERT_MSG ((boost::is_base_of<boost::graph_detail::stable_tag, VertexIterStability>::value), "Named graphs cannot use vecS as vertex container and remove vertices; the lack of vertex descriptor stability (which iterator stability is a proxy for) means that the name -> vertex mapping would need to be completely rebuilt after each deletion. See https://svn.boost.org/trac/boost/ticket/7863 for more information and a test case.");
Chris@16 315 typedef typename BGL_NAMED_GRAPH::vertex_name_type vertex_name_type;
Chris@16 316 const vertex_name_type& vertex_name = extract_name(derived()[vertex]);
Chris@16 317 named_vertices.erase(vertex_name);
Chris@16 318 }
Chris@16 319
Chris@16 320 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 321 inline void BGL_NAMED_GRAPH::clearing_graph()
Chris@16 322 {
Chris@16 323 named_vertices.clear();
Chris@16 324 }
Chris@16 325
Chris@16 326 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 327 typename BGL_NAMED_GRAPH::extract_name_type::result_type
Chris@16 328 BGL_NAMED_GRAPH::extract_name(const bundled_vertex_property_type& property)
Chris@16 329 {
Chris@16 330 return named_vertices.key_extractor().extract(property);
Chris@16 331 }
Chris@16 332
Chris@16 333 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 334 optional<typename BGL_NAMED_GRAPH::vertex_descriptor>
Chris@16 335 BGL_NAMED_GRAPH::
Chris@16 336 vertex_by_property(const bundled_vertex_property_type& property)
Chris@16 337 {
Chris@16 338 return find_vertex(extract_name(property), *this);
Chris@16 339 }
Chris@16 340
Chris@16 341 /// Retrieve the vertex associated with the given name
Chris@16 342 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 343 optional<Vertex>
Chris@16 344 find_vertex(typename BGL_NAMED_GRAPH::vertex_name_type const& name,
Chris@16 345 const BGL_NAMED_GRAPH& g)
Chris@16 346 {
Chris@16 347 typedef typename BGL_NAMED_GRAPH::vertices_by_name_type
Chris@16 348 vertices_by_name_type;
Chris@16 349
Chris@16 350 // Retrieve the set of vertices indexed by name
Chris@16 351 vertices_by_name_type const& vertices_by_name
Chris@16 352 = g.named_vertices.template get<vertex_name_t>();
Chris@16 353
Chris@16 354 /// Look for a vertex with the given name
Chris@16 355 typename vertices_by_name_type::const_iterator iter
Chris@16 356 = vertices_by_name.find(name);
Chris@16 357
Chris@16 358 if (iter == vertices_by_name.end())
Chris@16 359 return optional<Vertex>(); // vertex not found
Chris@16 360 else
Chris@16 361 return *iter;
Chris@16 362 }
Chris@16 363
Chris@16 364 /// Retrieve the vertex associated with the given name, or add a new
Chris@16 365 /// vertex with that name if no such vertex is available.
Chris@16 366 /// Note: This is enabled only when the vertex property type is different
Chris@16 367 /// from the vertex name to avoid ambiguous overload problems with
Chris@16 368 /// the add_vertex() function that takes a vertex property.
Chris@16 369 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 370 typename disable_if<is_same<
Chris@16 371 typename BGL_NAMED_GRAPH::vertex_name_type,
Chris@16 372 VertexProperty
Chris@16 373 >,
Chris@16 374 Vertex>::type
Chris@16 375 add_vertex(typename BGL_NAMED_GRAPH::vertex_name_type const& name,
Chris@16 376 BGL_NAMED_GRAPH& g)
Chris@16 377 {
Chris@16 378 if (optional<Vertex> vertex = find_vertex(name, g))
Chris@16 379 /// We found the vertex, so return it
Chris@16 380 return *vertex;
Chris@16 381 else
Chris@16 382 /// There is no vertex with the given name, so create one
Chris@16 383 return add_vertex(g.vertex_constructor(name), g.derived());
Chris@16 384 }
Chris@16 385
Chris@16 386 /// Add an edge using vertex names to refer to the vertices
Chris@16 387 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 388 std::pair<typename graph_traits<Graph>::edge_descriptor, bool>
Chris@16 389 add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name,
Chris@16 390 typename BGL_NAMED_GRAPH::vertex_name_type const& v_name,
Chris@16 391 BGL_NAMED_GRAPH& g)
Chris@16 392 {
Chris@16 393 return add_edge(add_vertex(u_name, g.derived()),
Chris@16 394 add_vertex(v_name, g.derived()),
Chris@16 395 g.derived());
Chris@16 396 }
Chris@16 397
Chris@16 398 /// Add an edge using vertex descriptors or names to refer to the vertices
Chris@16 399 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 400 std::pair<typename graph_traits<Graph>::edge_descriptor, bool>
Chris@16 401 add_edge(typename BGL_NAMED_GRAPH::vertex_descriptor const& u,
Chris@16 402 typename BGL_NAMED_GRAPH::vertex_name_type const& v_name,
Chris@16 403 BGL_NAMED_GRAPH& g)
Chris@16 404 {
Chris@16 405 return add_edge(u,
Chris@16 406 add_vertex(v_name, g.derived()),
Chris@16 407 g.derived());
Chris@16 408 }
Chris@16 409
Chris@16 410 /// Add an edge using vertex descriptors or names to refer to the vertices
Chris@16 411 template<BGL_NAMED_GRAPH_PARAMS>
Chris@16 412 std::pair<typename graph_traits<Graph>::edge_descriptor, bool>
Chris@16 413 add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name,
Chris@16 414 typename BGL_NAMED_GRAPH::vertex_descriptor const& v,
Chris@16 415 BGL_NAMED_GRAPH& g)
Chris@16 416 {
Chris@16 417 return add_edge(add_vertex(u_name, g.derived()),
Chris@16 418 v,
Chris@16 419 g.derived());
Chris@16 420 }
Chris@16 421
Chris@16 422 // Overloads to support EdgeMutablePropertyGraph graphs
Chris@16 423 template <BGL_NAMED_GRAPH_PARAMS>
Chris@16 424 std::pair<typename graph_traits<Graph>::edge_descriptor, bool>
Chris@16 425 add_edge(typename BGL_NAMED_GRAPH::vertex_descriptor const& u,
Chris@16 426 typename BGL_NAMED_GRAPH::vertex_name_type const& v_name,
Chris@16 427 typename edge_property_type<Graph>::type const& p,
Chris@16 428 BGL_NAMED_GRAPH& g) {
Chris@16 429 return add_edge(u, add_vertex(v_name, g.derived()), p, g.derived());
Chris@16 430 }
Chris@16 431
Chris@16 432 template <BGL_NAMED_GRAPH_PARAMS>
Chris@16 433 std::pair<typename graph_traits<Graph>::edge_descriptor, bool>
Chris@16 434 add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name,
Chris@16 435 typename BGL_NAMED_GRAPH::vertex_descriptor const& v,
Chris@16 436 typename edge_property_type<Graph>::type const& p,
Chris@16 437 BGL_NAMED_GRAPH& g) {
Chris@16 438 return add_edge(add_vertex(u_name, g.derived()), v, p, g.derived());
Chris@16 439 }
Chris@16 440
Chris@16 441 template <BGL_NAMED_GRAPH_PARAMS>
Chris@16 442 std::pair<typename graph_traits<Graph>::edge_descriptor, bool>
Chris@16 443 add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name,
Chris@16 444 typename BGL_NAMED_GRAPH::vertex_name_type const& v_name,
Chris@16 445 typename edge_property_type<Graph>::type const& p,
Chris@16 446 BGL_NAMED_GRAPH& g) {
Chris@16 447 return add_edge(add_vertex(u_name, g.derived()),
Chris@16 448 add_vertex(v_name, g.derived()), p, g.derived());
Chris@16 449 }
Chris@16 450
Chris@16 451 #undef BGL_NAMED_GRAPH
Chris@16 452 #undef BGL_NAMED_GRAPH_PARAMS
Chris@16 453
Chris@16 454 /*******************************************************************
Chris@16 455 * Maybe named graph mixin *
Chris@16 456 *******************************************************************/
Chris@16 457
Chris@16 458 /**
Chris@16 459 * A graph mixin that can provide a mapping from names to vertices,
Chris@16 460 * and use that mapping to simplify creation and manipulation of
Chris@16 461 * graphs.
Chris@16 462 */
Chris@16 463 template<typename Graph, typename Vertex, typename VertexProperty,
Chris@16 464 typename ExtractName
Chris@16 465 = typename internal_vertex_name<VertexProperty>::type>
Chris@16 466 struct maybe_named_graph : public named_graph<Graph, Vertex, VertexProperty>
Chris@16 467 {
Chris@16 468 };
Chris@16 469
Chris@16 470 /**
Chris@16 471 * A graph mixin that can provide a mapping from names to vertices,
Chris@16 472 * and use that mapping to simplify creation and manipulation of
Chris@16 473 * graphs. This partial specialization turns off this functionality
Chris@16 474 * when the @c VertexProperty does not have an internal vertex name.
Chris@16 475 */
Chris@16 476 template<typename Graph, typename Vertex, typename VertexProperty>
Chris@16 477 struct maybe_named_graph<Graph, Vertex, VertexProperty, void>
Chris@16 478 {
Chris@16 479 /// The type of the "bundled" property, from which the name can be
Chris@16 480 /// extracted.
Chris@16 481 typedef typename lookup_one_property<VertexProperty, vertex_bundle_t>::type
Chris@16 482 bundled_vertex_property_type;
Chris@16 483
Chris@16 484 /// Notify the named_graph that we have added the given vertex. This
Chris@16 485 /// is a no-op.
Chris@16 486 void added_vertex(Vertex) { }
Chris@16 487
Chris@16 488 /// Notify the named_graph that we are removing the given
Chris@16 489 /// vertex. This is a no-op.
Chris@16 490 template <typename VertexIterStability>
Chris@16 491 void removing_vertex(Vertex, VertexIterStability) { }
Chris@16 492
Chris@16 493 /// Notify the named_graph that we are clearing the graph. This is a
Chris@16 494 /// no-op.
Chris@16 495 void clearing_graph() { }
Chris@16 496
Chris@16 497 /// Search for a vertex that has the given property (based on its
Chris@16 498 /// name). This always returns an empty optional<>
Chris@16 499 optional<Vertex>
Chris@16 500 vertex_by_property(const bundled_vertex_property_type&)
Chris@16 501 {
Chris@16 502 return optional<Vertex>();
Chris@16 503 }
Chris@16 504 };
Chris@16 505
Chris@16 506 } } // end namespace boost::graph
Chris@16 507
Chris@16 508 #endif // BOOST_GRAPH_NAMED_GRAPH_HPP