1 // (C) Copyright 2007-2009 Andrew Sutton
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)
7 #ifndef BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
8 #define BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
10 #include <boost/graph/property_maps/container_property_map.hpp>
14 // This property map is built specifically for property maps over
15 // matrices. Like the basic property map over a container, this builds
16 // the property abstraction over a matrix (usually a vector of vectors)
17 // and returns property maps over the nested containers.
18 template <typename Graph, typename Key, typename Matrix>
19 struct matrix_property_map
20 : boost::put_get_helper<
21 container_property_map<Graph, Key, typename Matrix::value_type>,
22 matrix_property_map<Graph, Key, Matrix> >
24 // abstract the indexing keys
25 typedef typename detail::choose_indexer<Graph, Key>::indexer_type indexer_type;
27 // aliases for the nested container and its corresponding map
28 typedef typename Matrix::value_type container_type;
29 typedef container_property_map<Graph, Key, container_type> map_type;
33 // This property map doesn't really provide access to nested containers,
34 // but returns property maps over them. Since property maps are all
35 // copy-constructible (or should be anyways), we never return references.
36 // As such, this property is only readable, but not writable. Curiously,
37 // the inner property map is actually an lvalue pmap.
38 typedef map_type value_type;
39 typedef map_type reference;
40 typedef readable_property_map_tag category;
43 : m_matrix(0), m_graph(0)
46 matrix_property_map(Matrix& m, const Graph& g)
47 : m_matrix(&m), m_graph(const_cast<Graph*>(&g))
50 matrix_property_map(const matrix_property_map& x)
51 : m_matrix(x.m_matrix), m_graph(x.m_graph)
54 inline reference operator [](key_type k) const
56 typedef typename indexer_type::value_type Index;
57 Index x = indexer_type::index(k, *m_graph);
58 return map_type((*m_matrix)[x], *m_graph);
62 mutable Matrix* m_matrix;
63 mutable Graph* m_graph;