Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:21

0001 // (C) Copyright 2007-2009 Andrew Sutton
0002 //
0003 // Use, modification and distribution are subject to the
0004 // Boost Software License, Version 1.0 (See accompanying file
0005 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
0008 #define BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
0009 
0010 #include <boost/graph/property_maps/container_property_map.hpp>
0011 
0012 namespace boost
0013 {
0014 // This property map is built specifically for property maps over
0015 // matrices. Like the basic property map over a container, this builds
0016 // the property abstraction over a matrix (usually a vector of vectors)
0017 // and returns property maps over the nested containers.
0018 template < typename Graph, typename Key, typename Matrix >
0019 struct matrix_property_map
0020 : boost::put_get_helper<
0021       container_property_map< Graph, Key, typename Matrix::value_type >,
0022       matrix_property_map< Graph, Key, Matrix > >
0023 {
0024     // abstract the indexing keys
0025     typedef typename detail::choose_indexer< Graph, Key >::indexer_type
0026         indexer_type;
0027 
0028     // aliases for the nested container and its corresponding map
0029     typedef typename Matrix::value_type container_type;
0030     typedef container_property_map< Graph, Key, container_type > map_type;
0031 
0032     typedef Key key_type;
0033 
0034     // This property map doesn't really provide access to nested containers,
0035     // but returns property maps over them. Since property maps are all
0036     // copy-constructible (or should be anyways), we never return references.
0037     // As such, this property is only readable, but not writable. Curiously,
0038     // the inner property map is actually an lvalue pmap.
0039     typedef map_type value_type;
0040     typedef map_type reference;
0041     typedef readable_property_map_tag category;
0042 
0043     matrix_property_map() : m_matrix(0), m_graph(0) {}
0044 
0045     matrix_property_map(Matrix& m, const Graph& g)
0046     : m_matrix(&m), m_graph(const_cast< Graph* >(&g))
0047     {
0048     }
0049 
0050     matrix_property_map(const matrix_property_map& x)
0051     : m_matrix(x.m_matrix), m_graph(x.m_graph)
0052     {
0053     }
0054 
0055     inline reference operator[](key_type k) const
0056     {
0057         typedef typename indexer_type::value_type Index;
0058         Index x = indexer_type::index(k, *m_graph);
0059         return map_type((*m_matrix)[x], *m_graph);
0060     }
0061 
0062 private:
0063     mutable Matrix* m_matrix;
0064     mutable Graph* m_graph;
0065 };
0066 }
0067 
0068 #endif