Chris@16
|
1 // (C) Copyright 2007-2009 Andrew Sutton
|
Chris@16
|
2 //
|
Chris@16
|
3 // Use, modification and distribution are subject to the
|
Chris@16
|
4 // Boost Software License, Version 1.0 (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #ifndef BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
|
Chris@16
|
8 #define BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
|
Chris@16
|
9
|
Chris@16
|
10 #include <boost/graph/property_maps/container_property_map.hpp>
|
Chris@16
|
11
|
Chris@16
|
12 namespace boost
|
Chris@16
|
13 {
|
Chris@16
|
14 // This property map is built specifically for property maps over
|
Chris@16
|
15 // matrices. Like the basic property map over a container, this builds
|
Chris@16
|
16 // the property abstraction over a matrix (usually a vector of vectors)
|
Chris@16
|
17 // and returns property maps over the nested containers.
|
Chris@16
|
18 template <typename Graph, typename Key, typename Matrix>
|
Chris@16
|
19 struct matrix_property_map
|
Chris@16
|
20 : boost::put_get_helper<
|
Chris@16
|
21 container_property_map<Graph, Key, typename Matrix::value_type>,
|
Chris@16
|
22 matrix_property_map<Graph, Key, Matrix> >
|
Chris@16
|
23 {
|
Chris@16
|
24 // abstract the indexing keys
|
Chris@16
|
25 typedef typename detail::choose_indexer<Graph, Key>::indexer_type indexer_type;
|
Chris@16
|
26
|
Chris@16
|
27 // aliases for the nested container and its corresponding map
|
Chris@16
|
28 typedef typename Matrix::value_type container_type;
|
Chris@16
|
29 typedef container_property_map<Graph, Key, container_type> map_type;
|
Chris@16
|
30
|
Chris@16
|
31 typedef Key key_type;
|
Chris@16
|
32
|
Chris@16
|
33 // This property map doesn't really provide access to nested containers,
|
Chris@16
|
34 // but returns property maps over them. Since property maps are all
|
Chris@16
|
35 // copy-constructible (or should be anyways), we never return references.
|
Chris@16
|
36 // As such, this property is only readable, but not writable. Curiously,
|
Chris@16
|
37 // the inner property map is actually an lvalue pmap.
|
Chris@16
|
38 typedef map_type value_type;
|
Chris@16
|
39 typedef map_type reference;
|
Chris@16
|
40 typedef readable_property_map_tag category;
|
Chris@16
|
41
|
Chris@16
|
42 matrix_property_map()
|
Chris@16
|
43 : m_matrix(0), m_graph(0)
|
Chris@16
|
44 { }
|
Chris@16
|
45
|
Chris@16
|
46 matrix_property_map(Matrix& m, const Graph& g)
|
Chris@16
|
47 : m_matrix(&m), m_graph(const_cast<Graph*>(&g))
|
Chris@16
|
48 { }
|
Chris@16
|
49
|
Chris@16
|
50 matrix_property_map(const matrix_property_map& x)
|
Chris@16
|
51 : m_matrix(x.m_matrix), m_graph(x.m_graph)
|
Chris@16
|
52 { }
|
Chris@16
|
53
|
Chris@16
|
54 inline reference operator [](key_type k) const
|
Chris@16
|
55 {
|
Chris@16
|
56 typedef typename indexer_type::value_type Index;
|
Chris@16
|
57 Index x = indexer_type::index(k, *m_graph);
|
Chris@16
|
58 return map_type((*m_matrix)[x], *m_graph);
|
Chris@16
|
59 }
|
Chris@16
|
60
|
Chris@16
|
61 private:
|
Chris@16
|
62 mutable Matrix* m_matrix;
|
Chris@16
|
63 mutable Graph* m_graph;
|
Chris@16
|
64 };
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 #endif
|