Chris@16: // (C) Copyright 2007-2009 Andrew Sutton Chris@16: // Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0 (See accompanying file Chris@16: // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP Chris@16: #define BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: // This property map is built specifically for property maps over Chris@16: // matrices. Like the basic property map over a container, this builds Chris@16: // the property abstraction over a matrix (usually a vector of vectors) Chris@16: // and returns property maps over the nested containers. Chris@16: template Chris@16: struct matrix_property_map Chris@16: : boost::put_get_helper< Chris@16: container_property_map, Chris@16: matrix_property_map > Chris@16: { Chris@16: // abstract the indexing keys Chris@16: typedef typename detail::choose_indexer::indexer_type indexer_type; Chris@16: Chris@16: // aliases for the nested container and its corresponding map Chris@16: typedef typename Matrix::value_type container_type; Chris@16: typedef container_property_map map_type; Chris@16: Chris@16: typedef Key key_type; Chris@16: Chris@16: // This property map doesn't really provide access to nested containers, Chris@16: // but returns property maps over them. Since property maps are all Chris@16: // copy-constructible (or should be anyways), we never return references. Chris@16: // As such, this property is only readable, but not writable. Curiously, Chris@16: // the inner property map is actually an lvalue pmap. Chris@16: typedef map_type value_type; Chris@16: typedef map_type reference; Chris@16: typedef readable_property_map_tag category; Chris@16: Chris@16: matrix_property_map() Chris@16: : m_matrix(0), m_graph(0) Chris@16: { } Chris@16: Chris@16: matrix_property_map(Matrix& m, const Graph& g) Chris@16: : m_matrix(&m), m_graph(const_cast(&g)) Chris@16: { } Chris@16: Chris@16: matrix_property_map(const matrix_property_map& x) Chris@16: : m_matrix(x.m_matrix), m_graph(x.m_graph) Chris@16: { } Chris@16: Chris@16: inline reference operator [](key_type k) const Chris@16: { Chris@16: typedef typename indexer_type::value_type Index; Chris@16: Index x = indexer_type::index(k, *m_graph); Chris@16: return map_type((*m_matrix)[x], *m_graph); Chris@16: } Chris@16: Chris@16: private: Chris@16: mutable Matrix* m_matrix; Chris@16: mutable Graph* m_graph; Chris@16: }; Chris@16: } Chris@16: Chris@16: #endif