]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright 2007-2009 Andrew Sutton |
2 | // | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0 (See accompanying file | |
5 | // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_GRAPH_EXTERIOR_PROPERTY_HPP | |
8 | #define BOOST_GRAPH_EXTERIOR_PROPERTY_HPP | |
9 | ||
10 | #include <vector> | |
11 | #include <boost/graph/property_maps/container_property_map.hpp> | |
12 | #include <boost/graph/property_maps/matrix_property_map.hpp> | |
13 | ||
14 | namespace boost { | |
15 | namespace detail { | |
16 | // The vector matrix provides a little abstraction over vector | |
92f5a8d4 | 17 | // types that makes matrices easier to work with. |
7c673cae FG |
18 | template <typename Value> |
19 | struct vector_matrix | |
20 | { | |
21 | typedef std::vector<Value> container_type; | |
22 | typedef std::vector<container_type> matrix_type; | |
23 | ||
24 | typedef container_type value_type; | |
25 | typedef container_type& reference; | |
26 | typedef const container_type const_reference; | |
27 | typedef container_type* pointer; | |
28 | typedef typename matrix_type::size_type size_type; | |
29 | ||
92f5a8d4 | 30 | // Instantiate the matrix over n elements (creates an n by n matrix). |
7c673cae FG |
31 | // The graph has to be passed in order to ensure the index maps |
32 | // are constructed correctly when returning indexible elements. | |
33 | inline vector_matrix(size_type n) | |
34 | : m_matrix(n, container_type(n)) | |
35 | { } | |
36 | ||
37 | inline reference operator [](size_type n) | |
38 | { return m_matrix[n]; } | |
39 | ||
40 | inline const_reference operator [](size_type n) const | |
41 | { return m_matrix[n]; } | |
42 | ||
43 | matrix_type m_matrix; | |
44 | }; | |
45 | } /* namespace detail */ | |
46 | ||
47 | /** | |
48 | * The exterior_property metafunction defines an appropriate set of types for | |
49 | * creating an exterior property. An exterior property is comprised of a both | |
50 | * a container and a property map that acts as its abstraction. An extension | |
51 | * of this metafunction will select an appropriate "matrix" property that | |
52 | * records values for pairs of vertices. | |
53 | * | |
54 | * @todo This does not currently support the ability to define exterior | |
55 | * properties for graph types that do not model the IndexGraph concepts. A | |
56 | * solution should not be especially difficult, but will require an extension | |
57 | * of type traits to affect the type selection. | |
58 | */ | |
59 | template <typename Graph, typename Key, typename Value> | |
60 | struct exterior_property | |
61 | { | |
62 | typedef Key key_type; | |
63 | typedef Value value_type; | |
64 | ||
65 | typedef std::vector<Value> container_type; | |
66 | typedef container_property_map<Graph, Key, container_type> map_type; | |
67 | ||
68 | typedef detail::vector_matrix<Value> matrix_type; | |
69 | typedef matrix_property_map<Graph, Key, matrix_type> matrix_map_type; | |
70 | ||
71 | private: | |
72 | exterior_property() { } | |
73 | exterior_property(const exterior_property&) { } | |
74 | }; | |
75 | ||
76 | /** | |
77 | * Define a the container and property map types requried to create an exterior | |
78 | * vertex property for the given value type. The Graph parameter is required to | |
79 | * model the VertexIndexGraph concept. | |
80 | */ | |
81 | template <typename Graph, typename Value> | |
82 | struct exterior_vertex_property | |
83 | { | |
84 | typedef exterior_property< | |
85 | Graph, typename graph_traits<Graph>::vertex_descriptor, Value | |
86 | > property_type; | |
87 | typedef typename property_type::key_type key_type; | |
88 | typedef typename property_type::value_type value_type; | |
89 | typedef typename property_type::container_type container_type; | |
90 | typedef typename property_type::map_type map_type; | |
91 | typedef typename property_type::matrix_type matrix_type; | |
92 | typedef typename property_type::matrix_map_type matrix_map_type; | |
93 | }; | |
94 | ||
95 | /** | |
96 | * Define a the container and property map types requried to create an exterior | |
97 | * edge property for the given value type. The Graph parameter is required to | |
98 | * model the EdgeIndexGraph concept. | |
99 | */ | |
100 | template <typename Graph, typename Value> | |
101 | struct exterior_edge_property | |
102 | { | |
103 | typedef exterior_property< | |
104 | Graph, typename graph_traits<Graph>::edge_descriptor, Value | |
105 | > property_type; | |
106 | typedef typename property_type::key_type key_type; | |
107 | typedef typename property_type::value_type value_type; | |
108 | typedef typename property_type::container_type container_type; | |
109 | typedef typename property_type::map_type map_type; | |
110 | typedef typename property_type::matrix_type matrix_type; | |
111 | typedef typename property_type::matrix_map_type matrix_map_type; | |
112 | }; | |
113 | ||
114 | } /* namespace boost */ | |
115 | ||
116 | #endif |