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_CONTAINER_PROPERTY_MAP_HPP
0008 #define BOOST_GRAPH_CONTAINER_PROPERTY_MAP_HPP
0009 
0010 #include <boost/graph/detail/index.hpp>
0011 #include <boost/property_map/property_map.hpp>
0012 
0013 namespace boost
0014 {
0015 // This is an adapter built over the iterator property map with
0016 // more useful uniform construction semantics. Specifically, this
0017 // requires the container rather than the iterator and the graph
0018 // rather than the optional index map.
0019 template < typename Graph, typename Key, typename Container >
0020 struct container_property_map
0021 : public boost::put_get_helper<
0022       typename iterator_property_map< typename Container::iterator,
0023           typename property_map< Graph,
0024               typename detail::choose_indexer< Graph,
0025                   Key >::index_type >::type >::reference,
0026       container_property_map< Graph, Key, Container > >
0027 {
0028     typedef typename detail::choose_indexer< Graph, Key >::indexer_type
0029         indexer_type;
0030     typedef typename indexer_type::index_type index_type;
0031     typedef iterator_property_map< typename Container::iterator,
0032         typename property_map< Graph, index_type >::type >
0033         map_type;
0034     typedef typename map_type::key_type key_type;
0035     typedef typename map_type::value_type value_type;
0036     typedef typename map_type::reference reference;
0037     typedef typename map_type::category category;
0038 
0039     // The default constructor will *probably* crash if its actually
0040     // used for referencing vertices since the underlying iterator
0041     // map points past the end of an unknown container.
0042     inline container_property_map() : m_map() {}
0043 
0044     // This is the preferred constructor. It is invoked over the container
0045     // and the graph explicitly. This requires that the underlying iterator
0046     // map use the indices of the vertices in g rather than the default
0047     // identity map.
0048     //
0049     // Note the const-cast this ensures the reference type of the
0050     // vertex index map is non-const, which happens to be an
0051     // artifact of passing const graph references.
0052     inline container_property_map(Container& c, const Graph& g)
0053     : m_map(c.begin(), indexer_type::index_map(const_cast< Graph& >(g)))
0054     {
0055     }
0056 
0057     // Typical copy constructor.
0058     inline container_property_map(const container_property_map& x)
0059     : m_map(x.m_map)
0060     {
0061     }
0062 
0063     // The [] operator delegates to the underlying map/
0064     inline reference operator[](const key_type& k) const { return m_map[k]; }
0065 
0066     map_type m_map;
0067 };
0068 }
0069 
0070 #endif