Chris@16: // (C) Copyright 2007-2009 Andrew Sutton Chris@16: // Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0 (See accompanying file Chris@16: // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GRAPH_CONTAINER_PROPERTY_MAP_HPP Chris@16: #define BOOST_GRAPH_CONTAINER_PROPERTY_MAP_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: // This is an adapter built over the iterator property map with Chris@16: // more useful uniform construction semantics. Specifically, this Chris@16: // requires the container rather than the iterator and the graph Chris@16: // rather than the optional index map. Chris@16: template Chris@16: struct container_property_map Chris@16: : public boost::put_get_helper< Chris@16: typename iterator_property_map< Chris@16: typename Container::iterator, Chris@16: typename property_map< Chris@16: Graph, Chris@16: typename detail::choose_indexer::index_type Chris@16: >::type Chris@16: >::reference, Chris@16: container_property_map Chris@16: > Chris@16: { Chris@16: typedef typename detail::choose_indexer::indexer_type indexer_type; Chris@16: typedef typename indexer_type::index_type index_type; Chris@16: typedef iterator_property_map< Chris@16: typename Container::iterator, Chris@16: typename property_map::type Chris@16: > map_type; Chris@16: typedef typename map_type::key_type key_type; Chris@16: typedef typename map_type::value_type value_type; Chris@16: typedef typename map_type::reference reference; Chris@16: typedef typename map_type::category category; Chris@16: Chris@16: // The default constructor will *probably* crash if its actually Chris@16: // used for referencing vertices since the underlying iterator Chris@16: // map points past the end of an unknown container. Chris@16: inline container_property_map() Chris@16: : m_map() Chris@16: { } Chris@16: Chris@16: // This is the preferred constructor. It is invoked over the container Chris@16: // and the graph explicitly. This requires that the underlying iterator Chris@16: // map use the indices of the vertices in g rather than the default Chris@16: // identity map. Chris@16: // Chris@16: // Note the const-cast this ensures the reference type of the Chris@16: // vertex index map is non-const, which happens to be an Chris@16: // artifact of passing const graph references. Chris@16: inline container_property_map(Container& c, const Graph& g) Chris@16: : m_map(c.begin(), indexer_type::index_map(const_cast(g))) Chris@16: { } Chris@16: Chris@16: // Typical copy constructor. Chris@16: inline container_property_map(const container_property_map& x) Chris@16: : m_map(x.m_map) Chris@16: { } Chris@16: Chris@16: // The [] operator delegates to the underlying map/ Chris@16: inline reference operator [](const key_type& k) const Chris@16: { return m_map[k]; } Chris@16: Chris@16: map_type m_map; Chris@16: }; Chris@16: } Chris@16: Chris@16: #endif