File: container_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 (75 lines) | stat: -rw-r--r-- 3,034 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
68
69
70
71
72
73
74
75
// (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_CONTAINER_PROPERTY_MAP_HPP
#define BOOST_GRAPH_CONTAINER_PROPERTY_MAP_HPP

#include <boost/graph/detail/index.hpp>
#include <boost/property_map/property_map.hpp>

namespace boost
{
    // This is an adapter built over the iterator property map with
    // more useful uniform construction semantics. Specifically, this
    // requires the container rather than the iterator and the graph
    // rather than the optional index map.
    template <typename Graph, typename Key, typename Container>
    struct container_property_map
        : public boost::put_get_helper<
                typename iterator_property_map<
                        typename Container::iterator,
                        typename property_map<
                                Graph,
                                typename detail::choose_indexer<Graph, Key>::index_type
                            >::type
                    >::reference,
                    container_property_map<Graph, Key, Container>
            >
    {
        typedef typename detail::choose_indexer<Graph, Key>::indexer_type indexer_type;
        typedef typename indexer_type::index_type index_type;
        typedef iterator_property_map<
                typename Container::iterator,
                typename property_map<Graph, index_type>::type
            > map_type;
        typedef typename map_type::key_type key_type;
        typedef typename map_type::value_type value_type;
        typedef typename map_type::reference reference;
        typedef typename map_type::category category;

        // The default constructor will *probably* crash if its actually
        // used for referencing vertices since the underlying iterator
        // map points past the end of an unknown container.
        inline container_property_map()
            : m_map()
        { }

        // This is the preferred constructor. It is invoked over the container
        // and the graph explicitly. This requires that the underlying iterator
        // map use the indices of the vertices in g rather than the default
        // identity map.
        //
        // Note the const-cast this ensures the reference type of the
        // vertex index map is non-const, which happens to be an
        // artifact of passing const graph references.
        inline container_property_map(Container& c, const Graph& g)
            : m_map(c.begin(), indexer_type::index_map(const_cast<Graph&>(g)))
        { }

        // Typical copy constructor.
        inline container_property_map(const container_property_map& x)
            : m_map(x.m_map)
        { }

        // The [] operator delegates to the underlying map/
        inline reference operator [](const key_type& k) const
        { return m_map[k];  }

        map_type m_map;
    };
}

#endif