PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/graph/property_maps/matrix_property_map.hpp

http://hadesmem.googlecode.com/
C++ Header | 67 lines | 39 code | 12 blank | 16 comment | 0 complexity | 196f5d3f2fa1b69c57af3c461201fc2a MD5 | raw file
 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_MATRIX_PROPERTY_MAP_HPP
 8#define BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
 9
10#include <boost/graph/property_maps/container_property_map.hpp>
11
12namespace boost
13{
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> >
23    {
24        // abstract the indexing keys
25        typedef typename detail::choose_indexer<Graph, Key>::indexer_type indexer_type;
26
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;
30
31        typedef Key key_type;
32
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;
41
42        matrix_property_map()
43            : m_matrix(0), m_graph(0)
44        { }
45
46        matrix_property_map(Matrix& m, const Graph& g)
47            : m_matrix(&m), m_graph(const_cast<Graph*>(&g))
48        { }
49
50        matrix_property_map(const matrix_property_map& x)
51            : m_matrix(x.m_matrix), m_graph(x.m_graph)
52        { }
53
54        inline reference operator [](key_type k) const
55        {
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);
59        }
60
61    private:
62        mutable Matrix* m_matrix;
63        mutable Graph* m_graph;
64    };
65}
66
67#endif