File: matrix_property_map.hpp

package info (click to toggle)
boost1.62 1.62.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 686,420 kB
  • sloc: cpp: 2,609,004; xml: 972,558; ansic: 53,674; python: 32,437; sh: 8,829; asm: 3,071; cs: 2,121; makefile: 964; perl: 859; yacc: 472; php: 132; ruby: 94; f90: 55; sql: 13; csh: 6
file content (67 lines) | stat: -rw-r--r-- 2,501 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// (C) Copyright 2007-2009 Andrew Sutton
//
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0 (See accompanying file
// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP
#define BOOST_GRAPH_MATRIX_PROPERTY_MAP_HPP

#include <boost/graph/property_maps/container_property_map.hpp>

namespace boost
{
    // This property map is built specifically for property maps over
    // matrices. Like the basic property map over a container, this builds
    // the property abstraction over a matrix (usually a vector of vectors)
    // and returns property maps over the nested containers.
    template <typename Graph, typename Key, typename Matrix>
    struct matrix_property_map
        : boost::put_get_helper<
                container_property_map<Graph, Key, typename Matrix::value_type>,
                matrix_property_map<Graph, Key, Matrix> >
    {
        // abstract the indexing keys
        typedef typename detail::choose_indexer<Graph, Key>::indexer_type indexer_type;

        // aliases for the nested container and its corresponding map
        typedef typename Matrix::value_type container_type;
        typedef container_property_map<Graph, Key, container_type> map_type;

        typedef Key key_type;

        // This property map doesn't really provide access to nested containers,
        // but returns property maps over them. Since property maps are all
        // copy-constructible (or should be anyways), we never return references.
        // As such, this property is only readable, but not writable. Curiously,
        // the inner property map is actually an lvalue pmap.
        typedef map_type value_type;
        typedef map_type reference;
        typedef readable_property_map_tag category;

        matrix_property_map()
            : m_matrix(0), m_graph(0)
        { }

        matrix_property_map(Matrix& m, const Graph& g)
            : m_matrix(&m), m_graph(const_cast<Graph*>(&g))
        { }

        matrix_property_map(const matrix_property_map& x)
            : m_matrix(x.m_matrix), m_graph(x.m_graph)
        { }

        inline reference operator [](key_type k) const
        {
            typedef typename indexer_type::value_type Index;
            Index x = indexer_type::index(k, *m_graph);
            return map_type((*m_matrix)[x], *m_graph);
        }

    private:
        mutable Matrix* m_matrix;
        mutable Graph* m_graph;
    };
}

#endif